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 @@
1use git_repository as git;1use git_repository as git;
2 2
3/// A head reference will all commits that are 'governed' by it, that is are in its exclusive ancestry.3/// A head reference will all commits that are 'governed' by it, that is are in its exclusive ancestry.
4pub struct HistorySegment<'a> {4pub struct Segment<'a> {
5 pub _head: git::refs::Reference,5 pub _head: git::refs::Reference,
6 /// only relevant history items, that is those that change code in the respective crate.6 /// 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>,
8}8}
9 9
10pub struct HistoryItem {10pub struct Item {
11 pub id: git::hash::ObjectId,11 pub id: git::hash::ObjectId,
12 pub _message: git::bstr::BString,12 pub _message: git::bstr::BString,
13 pub tree_data: Vec<u8>,13 pub tree_data: Vec<u8>,
14}14}
15
16pub 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 @@
1pub mod history;
2
3pub 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
11};11};
12 12
13use crate::command::changelog_impl::commit;13use crate::command::changelog_impl::commit;
14use crate::command::changelog_impl::commit::History;
15use crate::utils::{component_to_bytes, is_tag_name, is_tag_version, package_by_name, tag_prefix};14use crate::utils::{component_to_bytes, is_tag_name, is_tag_version, package_by_name, tag_prefix};
16 15
17pub fn commit_history(repo: &git::Easy) -> anyhow::Result<Option<History>> {16pub fn commit_history(repo: &git::Easy) -> anyhow::Result<Option<commit::History>> {
18 let start = Instant::now();17 let start = Instant::now();
19 let prev = repo.object_cache_size(64 * 1024)?;18 let prev = repo.object_cache_size(64 * 1024)?;
20 let reference = match repo.head()?.peeled()?.kind {19 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
32 (commit.message.to_owned(), commit.tree())31 (commit.message.to_owned(), commit.tree())
33 };32 };
34 33
35 items.push(commit::HistoryItem {34 items.push(commit::history::Item {
36 id: commit_id.detach(),35 id: commit_id.detach(),
37 _message: message,36 _message: message,
38 tree_data: repo.find_object(tree_id)?.data.to_owned(),37 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
47 elapsed.as_secs_f32(),46 elapsed.as_secs_f32(),
48 items.len() as f32 / elapsed.as_secs_f32()47 items.len() as f32 / elapsed.as_secs_f32()
49 );48 );
50 Ok(Some(History {49 Ok(Some(commit::History {
51 head: reference.detach(),50 head: reference.detach(),
52 items,51 items,
53 }))52 }))
@@ -57,8 +56,8 @@ pub fn commit_history(repo: &git::Easy) -> anyhow::Result<Option<History>> { · 3 unmodified lines
57pub fn ref_segments<'h>(56pub fn ref_segments<'h>(
58 crate_name: &str,57 crate_name: &str,
59 ctx: &crate::Context,58 ctx: &crate::Context,
60 history: &'h History,59 history: &'h commit::History,
61) -> anyhow::Result<Vec<commit::HistorySegment<'h>>> {60) -> anyhow::Result<Vec<commit::history::Segment<'h>>> {
62 let meta = &ctx.meta;61 let meta = &ctx.meta;
63 let package = package_by_name(meta, crate_name)?;62 let package = package_by_name(meta, crate_name)?;
64 let tag_prefix = tag_prefix(package, &ctx.repo);63 let tag_prefix = tag_prefix(package, &ctx.repo);
@@ -100,7 +99,7 @@ pub fn ref_segments<'h>( · 35 unmodified lines
100 99
101 let start = Instant::now();100 let start = Instant::now();
102 let mut segments = Vec::new();101 let mut segments = Vec::new();
103 let mut segment = commit::HistorySegment {102 let mut segment = commit::history::Segment {
104 _head: history.head.to_owned(),103 _head: history.head.to_owned(),
105 history: vec![],104 history: vec![],
106 };105 };
@@ -181,7 +180,7 @@ pub fn ref_segments<'h>( · 74 unmodified lines
181 },180 },
182 Some(next_ref) => segments.push(std::mem::replace(181 Some(next_ref) => segments.push(std::mem::replace(
183 &mut segment,182 &mut segment,
184 commit::HistorySegment {183 commit::history::Segment {
185 _head: next_ref,184 _head: next_ref,
186 history: vec![item],185 history: vec![item],
187 },186 },

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