Skip to content

Commit

Permalink
chore: thanks clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed Mar 7, 2024
1 parent 1ca130f commit 104d23a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
3 changes: 2 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ docker-build: build-all
docker buildx build --platform linux/amd64,linux/arm/v7,linux/arm64/v8 . -t cocogitto/cog:latest -f docker/Dockerfile

changelog-inferno:
perf record --call-graph dwarf cog changelog
cargo build --release
perf record --call-graph dwarf target/release/cog changelog
perf script | inferno-collapse-perf > stacks.folded
cat stacks.folded | inferno-flamegraph > flamegraph.svg
chromium flamegraph.svg
Expand Down
9 changes: 3 additions & 6 deletions src/git/rev/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ static REPO_CACHE: Lazy<Arc<Mutex<BTreeMap<String, OidOf>>>> =

static FIRST_COMMIT: OnceCell<OidOf> = OnceCell::new();

// TODO: we need to handle the case where multiple tags point to the same commit Oid
pub(crate) fn get_cache(repository: &Repository) -> MutexGuard<'_, BTreeMap<String, OidOf>> {
let mut cache = REPO_CACHE.lock().unwrap();
if cache.is_empty() {
Expand All @@ -36,14 +35,12 @@ pub(crate) fn get_cache(repository: &Repository) -> MutexGuard<'_, BTreeMap<Stri
for tag in tag_iter {
if let Some(target) = tag.target.as_ref() {
let target = target.to_string();
cache.insert(target.clone(), OidOf::Tag(tag.clone()));
cache.insert(target[0..7].to_string(), OidOf::Tag(tag.clone()));
cache.insert(target, OidOf::Tag(tag.clone()));
}

if let Some(oid) = tag.oid.as_ref() {
let string = oid.to_string();
cache.insert(string.clone(), OidOf::Tag(tag.clone()));
cache.insert(string[0..7].to_string(), OidOf::Tag(tag.clone()));
let oid = oid.to_string();
cache.insert(oid, OidOf::Tag(tag.clone()));
}

cache.insert(tag.to_string(), OidOf::Tag(tag));
Expand Down
7 changes: 5 additions & 2 deletions src/git/rev/revspec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ impl Repository {
pub(super) fn resolve_oid_of(&self, from: &str) -> Result<OidOf, Git2Error> {
let cache = get_cache(self);

let oid = cache.get(from).cloned();
let oid = cache
.iter()
.find(|(k, _)| k.starts_with(from))
.map(|(_, v)| v);

match oid {
None => {
Expand All @@ -73,7 +76,7 @@ impl Repository {
.map_err(|_| Git2Error::UnknownRevision(from.to_string()))?;
Ok(OidOf::Other(object.id()))
}
Some(oid) => Ok(oid),
Some(oid) => Ok(oid.clone()),
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,7 @@ impl CocoGitto {
#[cfg(test)]
pub mod test_helpers {
use crate::git::repository::Repository;
use crate::git::rev::cache::get_cache;
use crate::CocoGitto;
use cmd_lib::{run_cmd, run_fun};
use std::collections::BTreeMap;

pub(crate) fn git_init_no_gpg() -> anyhow::Result<Repository> {
run_cmd!(
Expand Down
2 changes: 1 addition & 1 deletion tests/lib_tests/bump.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{BTreeMap, HashMap};
use std::collections::HashMap;
use std::path::Path;
use std::path::PathBuf;

Expand Down

0 comments on commit 104d23a

Please sign in to comment.