Repository::commit should accept parents as &[Commit], not just &[&Commit]
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 2.1k
- Forks
- 450
- Avg merge
- 11m
- Merged PRs (30d)
- 1
Description
If you want to generate a list of commits to pass to .commit as parents, the type &[&Commit] proves inconvenient, because it requires the caller to maintain ownership of the Commit objects for long enough to pass them. For instance, this could require generating a Vec<Commit>, and then an additional Vec<&Commit>.
Could Repository::commit accept a &[T] where T=AsRef, instead? That would allow both possibilities. It does, however, have the disadvantage that passing &[] will result in an ambiguous type, though. Another possibility would be always accepting &[Commit], but that would break existing code that passes &[&Commit].
I'd welcome other suggestions that would simplify code like this:
let mut parents : Vec<git2::Commit> = Vec::new();
parents.extend(tree.iter().filter_map(|e| {
if e.kind() == Some(git2::ObjectType::Commit) {
Some(repo.find_commit(e.id()).unwrap_or_else(die))
} else {
None
}
}));
let new_commit_oid = repo.commit(Some("SHEAD"), &author, &committer, &msg, &tree, &parents).unwrap_or_else(die);
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at Repository::commit and inspect its current parent argument and existing callers. Compare the proposed parent representations with compatibility concerns, especially the ambiguous empty-slice case. Done means an agreed API design that supports the intended parent collections without breaking existing callers, with the relevant behavior covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100