Skip to content

Commit 3ff991d

Browse files
committed
refactor (#301)
1 parent a331314 commit 3ff991d

File tree

8 files changed

+149
-158
lines changed

8 files changed

+149
-158
lines changed

gitoxide-core/src/repository/commit.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
use std::path::PathBuf;
2-
31
use anyhow::{Context, Result};
42
use git_repository as git;
53

64
pub fn describe(
7-
repo: impl Into<PathBuf>,
5+
repo: git::Repository,
86
rev_spec: Option<&str>,
97
mut out: impl std::io::Write,
108
mut err: impl std::io::Write,
@@ -18,7 +16,6 @@ pub fn describe(
1816
long_format,
1917
}: describe::Options,
2018
) -> Result<()> {
21-
let repo = git::open(repo)?.apply_environment();
2219
let commit = match rev_spec {
2320
Some(spec) => repo.rev_parse(spec)?.object()?.try_into_commit()?,
2421
None => repo.head_commit()?,

gitoxide-core/src/repository/exclude.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use anyhow::bail;
22
use std::io;
3-
use std::path::PathBuf;
43

54
use crate::OutputFormat;
65
use git_repository as git;
@@ -16,14 +15,13 @@ pub mod query {
1615
}
1716

1817
pub fn query(
19-
repository: PathBuf,
18+
repository: git::Repository,
2019
mut out: impl io::Write,
2120
query::Options { format, pathspecs }: query::Options,
2221
) -> anyhow::Result<()> {
2322
if format != OutputFormat::Human {
2423
bail!("JSON output isn't implemented yet");
2524
}
2625

27-
let repo = git::open(repository)?.apply_environment();
2826
todo!("impl");
2927
}

gitoxide-core/src/repository/mailmap.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{io, path::PathBuf};
1+
use std::io;
22

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

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

41-
let repo = git::open(repository)?.apply_environment();
4241
let mut mailmap = git::mailmap::Snapshot::default();
4342
if let Err(e) = repo.load_mailmap_into(&mut mailmap) {
4443
writeln!(err, "Error while loading mailmap, the first error is: {}", e).ok();

gitoxide-core/src/repository/odb.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{io, path::PathBuf};
1+
use std::io;
22

33
use anyhow::bail;
44
use git_repository as git;
@@ -22,7 +22,7 @@ mod info {
2222

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

34-
let repo = git::open(repository)?.apply_environment();
3534
let store = repo.objects.store_ref();
3635
let stats = info::Statistics {
3736
path: store.path().into(),
@@ -49,13 +48,11 @@ pub fn info(
4948
Ok(())
5049
}
5150

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

57-
let repo = git::open(repository)?.apply_environment();
58-
5956
for object in repo.objects.iter()? {
6057
let object = object?;
6158
writeln!(out, "{}", object)?;

gitoxide-core/src/repository/tree.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{borrow::Cow, io, path::PathBuf};
1+
use std::{borrow::Cow, io};
22

33
use anyhow::bail;
44
use git_repository as git;
@@ -117,7 +117,7 @@ mod entries {
117117

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

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

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

146145
pub fn entries(
147-
repository: PathBuf,
146+
repo: git::Repository,
148147
treeish: Option<&str>,
149148
recursive: bool,
150149
extended: bool,
@@ -155,7 +154,6 @@ pub fn entries(
155154
bail!("Only human output format is supported at the moment");
156155
}
157156

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

161159
if recursive {

gitoxide-core/src/repository/verify.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{path::PathBuf, sync::atomic::AtomicBool};
1+
use std::sync::atomic::AtomicBool;
22

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

2222
pub fn integrity(
23-
repo: PathBuf,
23+
repo: git::Repository,
2424
mut out: impl std::io::Write,
2525
progress: impl Progress,
2626
should_interrupt: &AtomicBool,
@@ -31,7 +31,6 @@ pub fn integrity(
3131
algorithm,
3232
}: Context,
3333
) -> anyhow::Result<()> {
34-
let repo = git_repository::open(repo)?;
3534
#[cfg_attr(not(feature = "serde1"), allow(unused))]
3635
let mut outcome = repo.objects.store_ref().verify_integrity(
3736
progress,

0 commit comments

Comments
 (0)