Skip to content

Commit

Permalink
refactor (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Apr 28, 2022
1 parent a331314 commit 3ff991d
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 158 deletions.
5 changes: 1 addition & 4 deletions gitoxide-core/src/repository/commit.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use std::path::PathBuf;

use anyhow::{Context, Result};
use git_repository as git;

pub fn describe(
repo: impl Into<PathBuf>,
repo: git::Repository,
rev_spec: Option<&str>,
mut out: impl std::io::Write,
mut err: impl std::io::Write,
Expand All @@ -18,7 +16,6 @@ pub fn describe(
long_format,
}: describe::Options,
) -> Result<()> {
let repo = git::open(repo)?.apply_environment();
let commit = match rev_spec {
Some(spec) => repo.rev_parse(spec)?.object()?.try_into_commit()?,
None => repo.head_commit()?,
Expand Down
4 changes: 1 addition & 3 deletions gitoxide-core/src/repository/exclude.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use anyhow::bail;
use std::io;
use std::path::PathBuf;

use crate::OutputFormat;
use git_repository as git;
Expand All @@ -16,14 +15,13 @@ pub mod query {
}

pub fn query(
repository: PathBuf,
repository: git::Repository,
mut out: impl io::Write,
query::Options { format, pathspecs }: query::Options,
) -> anyhow::Result<()> {
if format != OutputFormat::Human {
bail!("JSON output isn't implemented yet");
}

let repo = git::open(repository)?.apply_environment();
todo!("impl");
}
5 changes: 2 additions & 3 deletions gitoxide-core/src/repository/mailmap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{io, path::PathBuf};
use std::io;

use git_repository as git;
#[cfg(feature = "serde1")]
Expand Down Expand Up @@ -29,7 +29,7 @@ impl<'a> From<Entry<'a>> for JsonEntry {
}

pub fn entries(
repository: PathBuf,
repo: git::Repository,
format: OutputFormat,
#[cfg_attr(not(feature = "serde1"), allow(unused_variables))] out: impl io::Write,
mut err: impl io::Write,
Expand All @@ -38,7 +38,6 @@ pub fn entries(
writeln!(err, "Defaulting to JSON as human format isn't implemented").ok();
}

let repo = git::open(repository)?.apply_environment();
let mut mailmap = git::mailmap::Snapshot::default();
if let Err(e) = repo.load_mailmap_into(&mut mailmap) {
writeln!(err, "Error while loading mailmap, the first error is: {}", e).ok();
Expand Down
9 changes: 3 additions & 6 deletions gitoxide-core/src/repository/odb.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{io, path::PathBuf};
use std::io;

use anyhow::bail;
use git_repository as git;
Expand All @@ -22,7 +22,7 @@ mod info {

#[cfg_attr(not(feature = "serde1"), allow(unused_variables))]
pub fn info(
repository: PathBuf,
repo: git::Repository,
format: OutputFormat,
out: impl io::Write,
mut err: impl io::Write,
Expand All @@ -31,7 +31,6 @@ pub fn info(
writeln!(err, "Only JSON is implemented - using that instead")?;
}

let repo = git::open(repository)?.apply_environment();
let store = repo.objects.store_ref();
let stats = info::Statistics {
path: store.path().into(),
Expand All @@ -49,13 +48,11 @@ pub fn info(
Ok(())
}

pub fn entries(repository: PathBuf, format: OutputFormat, mut out: impl io::Write) -> anyhow::Result<()> {
pub fn entries(repo: git::Repository, format: OutputFormat, mut out: impl io::Write) -> anyhow::Result<()> {
if format != OutputFormat::Human {
bail!("Only human output format is supported at the moment");
}

let repo = git::open(repository)?.apply_environment();

for object in repo.objects.iter()? {
let object = object?;
writeln!(out, "{}", object)?;
Expand Down
8 changes: 3 additions & 5 deletions gitoxide-core/src/repository/tree.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{borrow::Cow, io, path::PathBuf};
use std::{borrow::Cow, io};

use anyhow::bail;
use git_repository as git;
Expand Down Expand Up @@ -117,7 +117,7 @@ mod entries {

#[cfg_attr(not(feature = "serde1"), allow(unused_variables))]
pub fn info(
repository: PathBuf,
repo: git::Repository,
treeish: Option<&str>,
extended: bool,
format: OutputFormat,
Expand All @@ -128,7 +128,6 @@ pub fn info(
writeln!(err, "Only JSON is implemented - using that instead")?;
}

let repo = git::open(repository)?.apply_environment();
let tree = treeish_to_tree(treeish, &repo)?;

let mut delegate = entries::Traverse::new(extended.then(|| &repo), None);
Expand All @@ -144,7 +143,7 @@ pub fn info(
}

pub fn entries(
repository: PathBuf,
repo: git::Repository,
treeish: Option<&str>,
recursive: bool,
extended: bool,
Expand All @@ -155,7 +154,6 @@ pub fn entries(
bail!("Only human output format is supported at the moment");
}

let repo = git::open(repository)?.apply_environment();
let tree = treeish_to_tree(treeish, &repo)?;

if recursive {
Expand Down
5 changes: 2 additions & 3 deletions gitoxide-core/src/repository/verify.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{path::PathBuf, sync::atomic::AtomicBool};
use std::sync::atomic::AtomicBool;

use git_repository as git;
use git_repository::Progress;
Expand All @@ -20,7 +20,7 @@ pub struct Context {
pub const PROGRESS_RANGE: std::ops::RangeInclusive<u8> = 1..=3;

pub fn integrity(
repo: PathBuf,
repo: git::Repository,
mut out: impl std::io::Write,
progress: impl Progress,
should_interrupt: &AtomicBool,
Expand All @@ -31,7 +31,6 @@ pub fn integrity(
algorithm,
}: Context,
) -> anyhow::Result<()> {
let repo = git_repository::open(repo)?;
#[cfg_attr(not(feature = "serde1"), allow(unused))]
let mut outcome = repo.objects.store_ref().verify_integrity(
progress,
Expand Down

0 comments on commit 3ff991d

Please sign in to comment.