Skip to content

Commit 0bf1d5b

Browse files
authored
Merge pull request #1884 from GitoxideLabs/improvements
various improvements
2 parents 339bdf8 + 5054780 commit 0bf1d5b

File tree

54 files changed

+224
-101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+224
-101
lines changed

gitoxide-core/src/repository/archive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn stream(
3030
let (mut stream, index) = repo.worktree_stream(tree)?;
3131
if !add_paths.is_empty() {
3232
let root = gix::path::realpath(
33-
repo.work_dir()
33+
repo.workdir()
3434
.ok_or_else(|| anyhow!("Adding files requires a worktree directory that contains them"))?,
3535
)?;
3636
for path in add_paths {

gitoxide-core/src/repository/attributes/query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub(crate) mod function {
8383
gix::worktree::stack::state::attributes::Source::WorktreeThenIdMapping
8484
.adjust_for_bare(repo.is_bare()),
8585
)?;
86-
let workdir = repo.work_dir();
86+
let workdir = repo.workdir();
8787
for pattern in pathspec.search().patterns() {
8888
let path = pattern.path();
8989
let entry = cache.at_entry(

gitoxide-core/src/repository/attributes/validate_baseline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pub(crate) mod function {
114114
};
115115
let work_dir = ignore
116116
.then(|| {
117-
repo.work_dir()
117+
repo.workdir()
118118
.map(ToOwned::to_owned)
119119
.ok_or_else(|| anyhow!("repository at {:?} must have a worktree checkout", repo.path()))
120120
})
@@ -249,7 +249,7 @@ pub(crate) mod function {
249249
}
250250
bail!(
251251
"{}: Validation failed with {} mismatches out of {}",
252-
gix::path::realpath(repo.work_dir().unwrap_or(repo.git_dir()))?.display(),
252+
gix::path::realpath(repo.workdir().unwrap_or(repo.git_dir()))?.display(),
253253
mismatches.len(),
254254
progress.counter().load(Ordering::Relaxed)
255255
);

gitoxide-core/src/repository/clean.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub(crate) mod function {
5353
if format != OutputFormat::Human {
5454
bail!("JSON output isn't implemented yet");
5555
}
56-
let Some(workdir) = repo.work_dir() else {
56+
let Some(workdir) = repo.workdir() else {
5757
bail!("Need a worktree to clean, this is a bare repository");
5858
};
5959

gitoxide-core/src/repository/exclude.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn query(
6060
let mut pathspec = repo.pathspec(
6161
true,
6262
patterns.iter(),
63-
repo.work_dir().is_some(),
63+
repo.workdir().is_some(),
6464
&index,
6565
gix::worktree::stack::state::attributes::Source::WorktreeThenIdMapping.adjust_for_bare(repo.is_bare()),
6666
)?;
@@ -82,12 +82,12 @@ pub fn query(
8282
let pathspec = repo.pathspec(
8383
true,
8484
patterns.iter(),
85-
repo.work_dir().is_some(),
85+
repo.workdir().is_some(),
8686
&index,
8787
gix::worktree::stack::state::attributes::Source::WorktreeThenIdMapping
8888
.adjust_for_bare(repo.is_bare()),
8989
)?;
90-
let workdir = repo.work_dir();
90+
let workdir = repo.workdir();
9191
for pattern in pathspec.search().patterns() {
9292
let path = pattern.path();
9393
let entry = cache.at_entry(

gitoxide-core/src/repository/merge/file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn file(
4040
let base_id = repo.rev_parse_single(base.as_bstr()).ok();
4141
let ours_id = repo.rev_parse_single(ours.as_bstr()).ok();
4242
let theirs_id = repo.rev_parse_single(theirs.as_bstr()).ok();
43-
let roots = worktree_roots(base_id, ours_id, theirs_id, repo.work_dir())?;
43+
let roots = worktree_roots(base_id, ours_id, theirs_id, repo.workdir())?;
4444

4545
let mut cache = repo.merge_resource_cache(roots)?;
4646
let null = repo.object_hash().null();

gix-fs/src/snapshot.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// TODO: tests
2-
use std::ops::Deref;
3-
42
use gix_features::threading::{get_mut, get_ref, MutableOnDemand, OwnShared};
3+
use std::ops::Deref;
54

65
/// A structure holding enough information to reload a value if its on-disk representation changes as determined by its modified time.
76
#[derive(Debug)]
@@ -39,6 +38,16 @@ impl<T: Clone + std::fmt::Debug> Clone for FileSnapshot<T> {
3938
}
4039
}
4140

41+
impl<T: Clone + std::fmt::Debug> FileSnapshot<T> {
42+
/// Return the contained instance if nobody else is holding it, or clone it otherwise.
43+
pub fn into_owned_or_cloned(self: OwnShared<Self>) -> T {
44+
match OwnShared::try_unwrap(self) {
45+
Ok(this) => this.value,
46+
Err(this) => this.value.clone(),
47+
}
48+
}
49+
}
50+
4251
/// A snapshot of a resource which is up-to-date in the moment it is retrieved.
4352
pub type SharedFileSnapshot<T> = OwnShared<FileSnapshot<T>>;
4453

File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)