MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / build_commit_message

Method build_commit_message

atomic-cli/src/commands/git/push.rs:176–219  ·  view source on GitHub ↗

Build a commit message with Atomic provenance trailers.

(
        &self,
        repo: &Repository,
        history: &[HistoryEntry],
        view: &str,
    )

Source from the content-addressed store, hash-verified

174impl Push {
175 /// Build a commit message with Atomic provenance trailers.
176 fn build_commit_message(
177 &self,
178 repo: &Repository,
179 history: &[HistoryEntry],
180 view: &str,
181 ) -> CliResult<String> {
182 // Use custom message or synthesize from change messages
183 let body = if let Some(ref msg) = self.message {
184 msg.clone()
185 } else {
186 self.synthesize_message(repo, history)
187 };
188
189 // Collect change hashes for trailers
190 let change_hashes: Vec<String> = history.iter().map(|e| e.hash.to_base32()).collect();
191
192 let merkle_state = history
193 .last()
194 .map(|e| e.state.to_base32())
195 .unwrap_or_default();
196
197 // Format: message + blank line + trailers
198 let mut msg = body;
199 msg.push_str("\n\n");
200 msg.push_str(&format!("Atomic-View: {}\n", view));
201 msg.push_str(&format!("Atomic-State: {}\n", merkle_state));
202
203 // For large change sets, only include the last 10 hashes inline
204 if change_hashes.len() <= 10 {
205 msg.push_str(&format!("Atomic-Changes: {}\n", change_hashes.join(", ")));
206 } else {
207 let last_10: Vec<&str> = change_hashes[change_hashes.len() - 10..]
208 .iter()
209 .map(|s| s.as_str())
210 .collect();
211 msg.push_str(&format!(
212 "Atomic-Changes: {} (+{} earlier)\n",
213 last_10.join(", "),
214 change_hashes.len() - 10
215 ));
216 }
217
218 Ok(msg)
219 }
220
221 /// Synthesize a commit message from Atomic change messages.
222 fn synthesize_message(&self, repo: &Repository, history: &[HistoryEntry]) -> String {

Callers 1

runMethod · 0.80

Calls 7

synthesize_messageMethod · 0.80
lastMethod · 0.80
cloneMethod · 0.45
iterMethod · 0.45
to_base32Method · 0.45
lenMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected