Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement object checkout in PrepareCheckout #1483

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions gix/src/clone/checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{clone::PrepareCheckout, Repository};
pub mod main_worktree {
use std::{path::PathBuf, sync::atomic::AtomicBool};

use crate::ext::ObjectIdExt;
use crate::{clone::PrepareCheckout, Progress, Repository};

/// The error returned by [`PrepareCheckout::main_worktree()`].
Expand Down Expand Up @@ -60,6 +61,13 @@ pub mod main_worktree {

/// Modification
impl PrepareCheckout {
/// Set the reference to checkout from the tree.
pub fn with_rev_single(mut self, object_id: Option<gix_hash::ObjectId>) -> PrepareCheckout {
self.checkout_object = object_id;

self
}

/// Checkout the main worktree, determining how many threads to use by looking at `checkout.workers`, defaulting to using
/// on thread per logical core.
///
Expand Down Expand Up @@ -97,8 +105,8 @@ pub mod main_worktree {
git_dir: repo.git_dir().to_owned(),
})?;

let root_tree_id = match &self.ref_name {
Some(reference_val) => Some(repo.find_reference(reference_val)?.peel_to_id_in_place()?),
let root_tree_id = match self.checkout_object {
Some(reference_val) => Some(reference_val.attach(repo)),
None => repo.head()?.try_peel_to_id_in_place()?,
};

Expand Down
23 changes: 16 additions & 7 deletions gix/src/clone/fetch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ pub enum Error {
},
#[error("Failed to update HEAD with values from remote")]
HeadUpdate(#[from] crate::reference::edit::Error),
#[cfg(feature = "revision")]
#[error("Failed to parse revision")]
RefParseError(#[from] crate::revision::spec::parse::single::Error),
#[error("The remote didn't have any ref that matched '{}'", wanted.as_ref().as_bstr())]
RefNameMissing { wanted: gix_ref::PartialName },
#[error("The remote has {} refs for '{}', try to use a specific name: {}", candidates.len(), wanted.as_ref().as_bstr(), candidates.iter().filter_map(|n| n.to_str().ok()).collect::<Vec<_>>().join(", "))]
Expand Down Expand Up @@ -229,13 +232,19 @@ impl PrepareFetch {
P::SubProgress: 'static,
{
let (repo, fetch_outcome) = self.fetch_only(progress, should_interrupt)?;
Ok((
crate::clone::PrepareCheckout {
repo: repo.into(),
ref_name: self.ref_name.clone(),
},
fetch_outcome,
))

let mut checkout = crate::clone::PrepareCheckout {
repo: repo.into(),
checkout_object: None,
};

if let Some(ref_name) = self.ref_name.as_ref() {
let bstring: &gix_ref::PartialNameRef = ref_name.as_ref();
let rev = checkout.repo().rev_parse_single(bstring.as_bstr())?.detach();
checkout = checkout.with_rev_single(Some(rev));
}

Ok((checkout, fetch_outcome))
}
}

Expand Down
4 changes: 2 additions & 2 deletions gix/src/clone/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ impl PrepareFetch {
pub struct PrepareCheckout {
/// A freshly initialized repository which is owned by us, or `None` if it was successfully checked out.
pub(self) repo: Option<crate::Repository>,
/// The name of the reference to check out. If `None`, the reference pointed to by `HEAD` will be checked out.
pub(self) ref_name: Option<gix_ref::PartialName>,
/// The object that will be checked out, or `None` if checking out HEAD.
pub(self) checkout_object: Option<gix_hash::ObjectId>,
}

// This module encapsulates functionality that works with both feature toggles. Can be combined with `fetch`
Expand Down
Loading