History

smart-release: refactor (#198)

Sebastian Thiel committed 5 years ago

Commit 87ebacc1 parent 4b48a143 files · +27 −24Browse files

Unified · Split

3 files
  1. cargo-smart-release/src/command/changelog/git.rs +6 −23
  2. cargo-smart-release/src/command/changelog/history.rs +14 −0
  3. cargo-smart-release/src/command/changelog/mod.rs +7 −1
cargo-smart-release/src/command/changelog/git.rs+6−23
@@ -8,27 +8,10 @@ use git_repository::{ · 7 unmodified lines
88 prelude::{CacheAccessExt, ObjectAccessExt, ReferenceAccessExt, ReferenceExt},
99 };
1010
11+use crate::command::changelog_impl::{history, History};
1112 use crate::utils::{component_to_bytes, is_tag_name, is_tag_version, package_by_name, tag_prefix};
1213 use std::cell::RefCell;
1314
14−/// A head reference will all commits that are 'governed' by it, that is are in its exclusive ancestry.
15−pub struct Segment<'a> {
16− _head: git::refs::Reference,
17− /// only relevant history items, that is those that change code in the respective crate.
18− history: Vec<&'a HistoryItem>,
19−}
20−
21−pub struct History {
22− head: git::refs::Reference,
23− items: Vec<HistoryItem>,
24−}
25−
26−pub struct HistoryItem {
27− id: git::hash::ObjectId,
28− _message: git::bstr::BString,
29− tree_data: Vec<u8>,
30−}
31−
3215 pub fn commit_history(repo: &git::Easy) -> anyhow::Result<Option<History>> {
3316 let start = Instant::now();
3417 let prev = repo.object_cache_size(64 * 1024)?;
@@ -47,7 +30,7 @@ pub fn commit_history(repo: &git::Easy) -> anyhow::Result<Option<History>> { · 12 unmodified lines
4730 (commit.message.to_owned(), commit.tree())
4831 };
4932
50− items.push(HistoryItem {
33+ items.push(history::Item {
5134 id: commit_id.detach(),
5235 _message: message,
5336 tree_data: repo.find_object(tree_id)?.data.to_owned(),
@@ -69,11 +52,11 @@ pub fn commit_history(repo: &git::Easy) -> anyhow::Result<Option<History>> { · 15 unmodified lines
6952 }
7053
7154 /// Return the head reference followed by all tags affecting `crate_name` as per our tag name rules, ordered by ancestry.
72−pub fn crate_references_descending<'h>(
55+pub fn ref_segments<'h>(
7356 crate_name: &str,
7457 ctx: &crate::Context,
7558 history: &'h History,
76−) -> anyhow::Result<Vec<Segment<'h>>> {
59+) -> anyhow::Result<Vec<history::Segment<'h>>> {
7760 let meta = &ctx.meta;
7861 let package = package_by_name(meta, crate_name)?;
7962 let tag_prefix = tag_prefix(package, &ctx.repo);
@@ -115,7 +98,7 @@ pub fn crate_references_descending<'h>( · 35 unmodified lines
11598
11699 let start = Instant::now();
117100 let mut segments = Vec::new();
118− let mut segment = Segment {
101+ let mut segment = history::Segment {
119102 _head: history.head.to_owned(),
120103 history: vec![],
121104 };
@@ -196,7 +179,7 @@ pub fn crate_references_descending<'h>( · 74 unmodified lines
196179 },
197180 Some(next_ref) => segments.push(std::mem::replace(
198181 &mut segment,
199− Segment {
182+ history::Segment {
200183 _head: next_ref,
201184 history: vec![item],
202185 },
cargo-smart-release/src/command/changelog/history.rs+14−0
@@ -0,0 +1,14 @@
1+use git_repository as git;
2+
3+/// A head reference will all commits that are 'governed' by it, that is are in its exclusive ancestry.
4+pub struct Segment<'a> {
5+ pub _head: git::refs::Reference,
6+ /// only relevant history items, that is those that change code in the respective crate.
7+ pub history: Vec<&'a Item>,
8+}
9+
10+pub struct Item {
11+ pub id: git::hash::ObjectId,
12+ pub _message: git::bstr::BString,
13+ pub tree_data: Vec<u8>,
14+}
cargo-smart-release/src/command/changelog/mod.rs+7−1
@@ -1,6 +1,12 @@
11 use crate::command::changelog::Options;
22
33 mod git;
4+mod history;
5+
6+pub struct History {
7+ head: git_repository::refs::Reference,
8+ items: Vec<history::Item>,
9+}
410
511 pub fn changelog(options: Options, crates: Vec<String>) -> anyhow::Result<()> {
612 let ctx = crate::Context::new(crates)?;
@@ -15,7 +21,7 @@ pub fn changelog(options: Options, crates: Vec<String>) -> anyhow::Result<()> { · 8 unmodified lines
1521 Some(history) => history,
1622 };
1723 for crate_name in &crate_names {
18− git::crate_references_descending(crate_name, &ctx, &history)?;
24+ let _segments = git::ref_segments(crate_name, &ctx, &history)?;
1925 }
2026
2127 Ok(())