History

smart-release: refactor (#198)

Sebastian Thiel committed 5 years ago

Commit 17322fa1 parent ac0696b3 files · +16 −16Browse files

Unified · Split

3 files
  1. cargo-smart-release/src/command/changelog/commit/history.rs +3 −8
  2. cargo-smart-release/src/command/changelog/commit/mod.rs +6 −0
  3. cargo-smart-release/src/command/changelog/git.rs +7 −8
cargo-smart-release/src/command/changelog/commit/history.rsrenamed from cargo-smart-release/src/command/changelog/commit.rs+3−8
@@ -1,19 +1,14 @@
11 use git_repository as git;
22
33 /// A head reference will all commits that are 'governed' by it, that is are in its exclusive ancestry.
4−pub struct HistorySegment<'a> {
4+pub struct Segment<'a> {
55 pub _head: git::refs::Reference,
66 /// only relevant history items, that is those that change code in the respective crate.
7− pub history: Vec<&'a HistoryItem>,
7+ pub history: Vec<&'a Item>,
88 }
99
10−pub struct HistoryItem {
10+pub struct Item {
1111 pub id: git::hash::ObjectId,
1212 pub _message: git::bstr::BString,
1313 pub tree_data: Vec<u8>,
1414 }
15−
16−pub struct History {
17− pub head: git_repository::refs::Reference,
18− pub items: Vec<HistoryItem>,
19−}
cargo-smart-release/src/command/changelog/commit/mod.rs+6−0
@@ -0,0 +1,6 @@
1+pub mod history;
2+
3+pub struct History {
4+ pub head: git_repository::refs::Reference,
5+ pub items: Vec<history::Item>,
6+}
cargo-smart-release/src/command/changelog/git.rs+7−8
@@ -11,10 +11,9 @@ use git_repository::{ · 10 unmodified lines
1111 };
1212
1313 use crate::command::changelog_impl::commit;
14−use crate::command::changelog_impl::commit::History;
1514 use crate::utils::{component_to_bytes, is_tag_name, is_tag_version, package_by_name, tag_prefix};
1615
17−pub fn commit_history(repo: &git::Easy) -> anyhow::Result<Option<History>> {
16+pub fn commit_history(repo: &git::Easy) -> anyhow::Result<Option<commit::History>> {
1817 let start = Instant::now();
1918 let prev = repo.object_cache_size(64 * 1024)?;
2019 let reference = match repo.head()?.peeled()?.kind {
@@ -32,7 +31,7 @@ pub fn commit_history(repo: &git::Easy) -> anyhow::Result<Option<History>> { · 11 unmodified lines
3231 (commit.message.to_owned(), commit.tree())
3332 };
3433
35− items.push(commit::HistoryItem {
34+ items.push(commit::history::Item {
3635 id: commit_id.detach(),
3736 _message: message,
3837 tree_data: repo.find_object(tree_id)?.data.to_owned(),
@@ -47,7 +46,7 @@ pub fn commit_history(repo: &git::Easy) -> anyhow::Result<Option<History>> { · 8 unmodified lines
4746 elapsed.as_secs_f32(),
4847 items.len() as f32 / elapsed.as_secs_f32()
4948 );
50− Ok(Some(History {
49+ Ok(Some(commit::History {
5150 head: reference.detach(),
5251 items,
5352 }))
@@ -57,8 +56,8 @@ pub fn commit_history(repo: &git::Easy) -> anyhow::Result<Option<History>> { · 3 unmodified lines
5756 pub fn ref_segments<'h>(
5857 crate_name: &str,
5958 ctx: &crate::Context,
60− history: &'h History,
61−) -> anyhow::Result<Vec<commit::HistorySegment<'h>>> {
59+ history: &'h commit::History,
60+) -> anyhow::Result<Vec<commit::history::Segment<'h>>> {
6261 let meta = &ctx.meta;
6362 let package = package_by_name(meta, crate_name)?;
6463 let tag_prefix = tag_prefix(package, &ctx.repo);
@@ -100,7 +99,7 @@ pub fn ref_segments<'h>( · 35 unmodified lines
10099
101100 let start = Instant::now();
102101 let mut segments = Vec::new();
103− let mut segment = commit::HistorySegment {
102+ let mut segment = commit::history::Segment {
104103 _head: history.head.to_owned(),
105104 history: vec![],
106105 };
@@ -181,7 +180,7 @@ pub fn ref_segments<'h>( · 74 unmodified lines
181180 },
182181 Some(next_ref) => segments.push(std::mem::replace(
183182 &mut segment,
184− commit::HistorySegment {
183+ commit::history::Segment {
185184 _head: next_ref,
186185 history: vec![item],
187186 },

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t