pub fn import_refs(
    tx: &mut Transaction,
    git_repo: &git2::Repository,
) -> Result<(), GitImportError> {
    let store = tx.store().clone();
    let git_refs = git_repo.references()?;
    let existing_git_refs: Vec<_> = tx.as_repo().view().git_refs().keys().cloned().collect();
    // TODO: Store the id of the previous import and read it back here, so we can
    // merge the views instead of overwriting.
    for existing_git_ref in existing_git_refs {
        tx.remove_git_ref(&existing_git_ref);
        // TODO: We should probably also remove heads pointing to the same
        // commits and commits no longer reachable from other refs.
        // If the underlying git repo has a branch that gets rewritten, we
        // should probably not keep the commits it used to point to.
    }
    for git_ref in git_refs {
        let git_ref = git_ref?;
        if !(git_ref.is_tag() || git_ref.is_branch() || git_ref.is_remote())
            || git_ref.name().is_none()
        {
            // Skip other refs (such as notes) and symbolic refs, as well as non-utf8 refs.
            // TODO: Is it useful to import HEAD (especially if it's detached)?
            continue;
        }
        let git_commit = git_ref.peel_to_commit()?;
        let id = CommitId(git_commit.id().as_bytes().to_vec());
        let commit = store.get_commit(&id).unwrap();
        tx.add_head(&commit);
        tx.insert_git_ref(git_ref.name().unwrap().to_string(), id);
        // For now, we consider all remotes "publishing".
        // TODO: Make it configurable which remotes are publishing.
        if git_ref.is_remote() {
            tx.add_public_head(&commit);
        }
    }
    Ok(())
}
// Reflect changes made in the underlying Git repo in the Jujube repo.
Reflect changes made in the underlying Git repo in the Jujube repo.
Reflect changes made in the underlying Git repo in the Jujube repo .
pub fn import_refs(
    tx: &mut Transaction,
    git_repo: &git2::Repository,
) -> Result<(), GitImportError> {
    let store = tx.store().clone();
    let git_refs = git_repo.references()?;
    let existing_git_refs: Vec<_> = tx.as_repo().view().git_refs().keys().cloned().collect();
    // TODO: Store the id of the previous import and read it back here, so we can
    // merge the views instead of overwriting.
    for existing_git_ref in existing_git_refs {
        tx.remove_git_ref(&existing_git_ref);
        // TODO: We should probably also remove heads pointing to the same
        // commits and commits no longer reachable from other refs.
        // If the underlying git repo has a branch that gets rewritten, we
        // should probably not keep the commits it used to point to.
    }
    for git_ref in git_refs {
        let git_ref = git_ref?;
        if !(git_ref.is_tag() || git_ref.is_branch() || git_ref.is_remote())
            || git_ref.name().is_none()
        {
            // Skip other refs (such as notes) and symbolic refs, as well as non-utf8 refs.
            // TODO: Is it useful to import HEAD (especially if it's detached)?
            continue;
        }
        let git_commit = git_ref.peel_to_commit()?;
        let id = CommitId(git_commit.id().as_bytes().to_vec());
        let commit = store.get_commit(&id).unwrap();
        tx.add_head(&commit);
        tx.insert_git_ref(git_ref.name().unwrap().to_string(), id);
        // For now, we consider all remotes "publishing".
        // TODO: Make it configurable which remotes are publishing.
        if git_ref.is_remote() {
            tx.add_public_head(&commit);
        }
    }
    Ok(())
}
pub fn import_refs ( tx : & mut Transaction , git_repo : & git2 :: Repository , ) -> Result < ( ) , GitImportError > { let store = tx . store ( ) . clone ( ) ; let git_refs = git_repo . references ( ) ? ; let existing_git_refs : Vec < _ > = tx . as_repo ( ) . view ( ) . git_refs ( ) . keys ( ) . cloned ( ) . collect ( ) ; // TODO: Store the id of the previous import and read it back here, so we can // merge the views instead of overwriting. for existing_git_ref in existing_git_refs { tx . remove_git_ref ( & existing_git_ref ) ; // TODO: We should probably also remove heads pointing to the same // commits and commits no longer reachable from other refs. // If the underlying git repo has a branch that gets rewritten, we // should probably not keep the commits it used to point to. } for git_ref in git_refs { let git_ref = git_ref ? ; if ! ( git_ref . is_tag ( ) || git_ref . is_branch ( ) || git_ref . is_remote ( ) ) || git_ref . name ( ) . is_none ( ) { // Skip other refs (such as notes) and symbolic refs, as well as non-utf8 refs. // TODO: Is it useful to import HEAD (especially if it's detached)? continue ; } let git_commit = git_ref . peel_to_commit ( ) ? ; let id = CommitId ( git_commit . id ( ) . as_bytes ( ) . to_vec ( ) ) ; let commit = store . get_commit ( & id ) . unwrap ( ) ; tx . add_head ( & commit ) ; tx . insert_git_ref ( git_ref . name ( ) . unwrap ( ) . to_string ( ) , id ) ; // For now, we consider all remotes "publishing". // TODO: Make it configurable which remotes are publishing. if git_ref . is_remote ( ) { tx . add_public_head ( & commit ) ; } } Ok ( ( ) ) }
Reflect changes made in the underlying Git repo in the Jujube repo.
Reflect changes made in the underlying Git repo in the Jujube repo .
tx
&mut Transaction
git_repo
&git2::Repository
tx
&mut Transaction
git_repo
&git2::Repository