Skip to content

Commit b588596

Browse files
committed
library:
added parelel as optinal (but default feature
1 parent e03202e commit b588596

File tree

7 files changed

+43
-9
lines changed

7 files changed

+43
-9
lines changed

TODO.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@
2323
- [ ] add more and better ways to filter dates
2424
- [x] add filters for git specific stuff like author, committer, etc
2525
- [ ] ability to get a git repo from a url using something like git clone
26+
- [ ] add support for other languages (currently only supports rust)

cargo-function-history/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ description = "cargo frontend for git-function-history"
1010

1111
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1212

13+
# [features]
14+
# default = ["parallel"]
15+
# parallel = ["git_function_history/parallel", "function_history_backend_thread/parallel"]
16+
# not-parallel = ["git_function_history/default-features"]
17+
1318
[dependencies]
1419
git_function_history = { path = "../git-function-history-lib", version = "0.6.0" }
1520
lazy_static = "1.3.0"

function_history_backend_thread/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ description = "threading and types for git-function-history"
1010

1111
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1212

13+
14+
# [features]
15+
# default = ["parallel"]
16+
# parallel = ["git_function_history/parallel"]
17+
# not-parallel = []
18+
1319
[dependencies]
1420
git_function_history = { path = "../git-function-history-lib", version = "0.6.1" }
1521
log = "0.4"

git-function-history-gui/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ description = "GUI frontend for git-function-history"
1010

1111
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1212

13+
# [features]
14+
# default = ["parallel"]
15+
# parallel = ["git_function_history/parallel", "function_history_backend_thread/parallel"]
16+
# not-parallel = ["git_function_history/default-features"]
17+
1318
[dependencies]
1419
eframe = {version = "0.19.0", features = ["dark-light"]}
1520
git_function_history = { path = "../git-function-history-lib", version = "0.6.0" }

git-function-history-lib/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ keywords = ["git_function_history", "git", "function", ]
88
categories = ["tools", "git"]
99
description = "show function history from git"
1010
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
11+
[features]
12+
default = ["parallel"]
13+
parallel = ["dep:rayon"]
1114

1215
[dependencies]
1316
chrono = "0.4.22"
1417
ra_ap_syntax = "0.0.131"
15-
rayon = "1.5.3"
18+
rayon = { version = "1.5.1", optional = true }

git-function-history-lib/src/lib.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@
1313
clippy::missing_errors_doc,
1414
clippy::return_self_not_must_use
1515
)]
16+
1617
/// Different types that can extracted from the result of `get_function_history`.
1718
pub mod types;
1819
use ra_ap_syntax::{
1920
ast::{self, HasDocComments, HasGenericParams, HasName},
2021
AstNode, SourceFile, SyntaxKind,
2122
};
23+
#[cfg(feature = "parallel")]
2224
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
2325

26+
2427
use std::{collections::HashMap, error::Error, process::Command};
2528
pub use types::{
2629
Block, BlockType, CommitFunctions, File, Function, FunctionBlock, FunctionHistory,
@@ -188,8 +191,11 @@ pub fn get_function_history(
188191
Err("file is not a rust file")?;
189192
}
190193
}
191-
file_history.commit_history = commits
192-
.par_iter()
194+
#[cfg(feature = "parallel")]
195+
let t = commits.par_iter();
196+
#[cfg(not(feature = "parallel"))]
197+
let t = commits.iter();
198+
file_history.commit_history = t
193199
.filter_map(|commit| {
194200
match &file {
195201
FileType::Absolute(path) => match find_function_in_commit(commit.0, path, name) {
@@ -566,8 +572,11 @@ fn find_function_in_commit_with_filetype(
566572
}
567573
}
568574
let err = "no function found".to_string();
569-
let returns: Vec<File> = files
570-
.par_iter()
575+
#[cfg(feature="parellel")]
576+
let t = files.par_iter();
577+
#[cfg(not(feature="parellel"))]
578+
let t = files.iter();
579+
let returns: Vec<File> = t
571580
.filter_map(|file| match find_function_in_commit(commit, file, name) {
572581
Ok(functions) => Some(File::new((*file).to_string(), functions)),
573582
Err(_) => None,

git-function-history-lib/src/types.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use chrono::{DateTime, FixedOffset};
2+
#[cfg(feature = "parallel")]
23
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
34
use std::{collections::HashMap, error::Error, fmt};
45

@@ -569,7 +570,7 @@ impl FunctionHistory {
569570
/// This will return a vector of all the commit hashess in the history.
570571
pub fn list_commit_hashes(&self) -> Vec<&str> {
571572
self.commit_history
572-
.par_iter()
573+
.iter()
573574
.map(|c| c.commit_hash.as_ref())
574575
.collect()
575576
}
@@ -647,9 +648,13 @@ impl FunctionHistory {
647648
/// history.filter_by(Filter::Directory("app".to_string())).unwrap();
648649
/// ```
649650
pub fn filter_by(&self, filter: &Filter) -> Result<Self, Box<dyn Error>> {
650-
let vec: Vec<CommitFunctions> = self
651-
.commit_history
652-
.par_iter()
651+
#[cfg(feature = "parallel")]
652+
let t = self
653+
.commit_history
654+
.par_iter();
655+
#[cfg(not(feature = "parallel"))]
656+
let t = self.commit_history.iter();
657+
let vec: Vec<CommitFunctions> = t
653658
.filter(|f| match filter {
654659
Filter::FunctionInLines(..)
655660
| Filter::FunctionWithParent(_)

0 commit comments

Comments
 (0)