node: Start working on git-fetch
Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
parent
15eed71588
commit
38f4bb52d8
|
|
@ -0,0 +1,24 @@
|
|||
use std::net;
|
||||
|
||||
use crate::identity::ProjId;
|
||||
use crate::storage::{Error, WriteStorage};
|
||||
|
||||
/// Default port of the `git` transport protocol.
|
||||
pub const PROTOCOL_PORT: u16 = 9418;
|
||||
|
||||
pub fn fetch<S: WriteStorage>(
|
||||
_proj: &ProjId,
|
||||
remote: &net::SocketAddr,
|
||||
mut storage: S,
|
||||
) -> Result<(), Error> {
|
||||
let _repo = storage.repository();
|
||||
|
||||
let url = format!("git://{}", remote);
|
||||
let refs: &[&str] = &[];
|
||||
let mut remote = git2::Remote::create_detached(&url)?;
|
||||
let mut opts = git2::FetchOptions::default();
|
||||
|
||||
remote.fetch(refs, Some(&mut opts), None)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ mod address_manager;
|
|||
mod clock;
|
||||
mod collections;
|
||||
mod decoder;
|
||||
mod git;
|
||||
mod hash;
|
||||
mod identity;
|
||||
mod logger;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ use crate::address_manager::AddressManager;
|
|||
use crate::clock::RefClock;
|
||||
use crate::collections::{HashMap, HashSet};
|
||||
use crate::decoder::Decoder;
|
||||
use crate::git;
|
||||
use crate::identity::{ProjId, UserId};
|
||||
use crate::storage;
|
||||
use crate::storage::{Inventory, ReadStorage, Remotes, Unverified, WriteStorage};
|
||||
|
|
@ -38,6 +39,7 @@ pub const MAX_CONNECTION_ATTEMPTS: usize = 3;
|
|||
#[derive(Debug)]
|
||||
pub enum Command {
|
||||
Connect(net::SocketAddr),
|
||||
Fetch(ProjId, net::SocketAddr),
|
||||
}
|
||||
|
||||
/// Message envelope. All messages sent over the network are wrapped in this type.
|
||||
|
|
@ -351,7 +353,7 @@ impl<T: ReadStorage + WriteStorage, S: address_book::Store> Protocol<S, T> {
|
|||
|
||||
impl<S, T> nakamoto::Protocol for Protocol<S, T>
|
||||
where
|
||||
T: ReadStorage + WriteStorage,
|
||||
T: ReadStorage + WriteStorage + 'static,
|
||||
S: address_book::Store,
|
||||
{
|
||||
type Event = ();
|
||||
|
|
@ -416,6 +418,9 @@ where
|
|||
|
||||
match cmd {
|
||||
Command::Connect(addr) => self.context.connect(addr),
|
||||
Command::Fetch(proj, remote) => {
|
||||
git::fetch(&proj, &remote, &mut self.storage).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::marker::PhantomData;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::path::Path;
|
||||
use std::{fmt, fs, io, net};
|
||||
use std::{fmt, fs, io};
|
||||
|
||||
use git_ref_format::refspec;
|
||||
use once_cell::sync::Lazy;
|
||||
|
|
@ -100,8 +100,7 @@ pub trait ReadStorage {
|
|||
}
|
||||
|
||||
pub trait WriteStorage {
|
||||
/// Fetch a project from a remote peer.
|
||||
fn fetch(&mut self, proj: &ProjId, remote: &net::SocketAddr) -> Result<(), Error>;
|
||||
fn repository(&mut self) -> &mut git2::Repository;
|
||||
}
|
||||
|
||||
impl<T, S> ReadStorage for T
|
||||
|
|
@ -121,10 +120,10 @@ where
|
|||
impl<T, S> WriteStorage for T
|
||||
where
|
||||
T: DerefMut<Target = S>,
|
||||
S: WriteStorage,
|
||||
S: WriteStorage + 'static,
|
||||
{
|
||||
fn fetch(&mut self, proj: &ProjId, remote: &net::SocketAddr) -> Result<(), Error> {
|
||||
self.deref_mut().fetch(proj, remote)
|
||||
fn repository(&mut self) -> &mut git2::Repository {
|
||||
self.deref_mut().repository()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -159,8 +158,8 @@ impl ReadStorage for Storage {
|
|||
}
|
||||
|
||||
impl WriteStorage for Storage {
|
||||
fn fetch(&mut self, _id: &ProjId, _remote: &net::SocketAddr) -> Result<(), Error> {
|
||||
todo!()
|
||||
fn repository(&mut self) -> &mut git2::Repository {
|
||||
&mut self.backend
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ impl<S> DerefMut for Peer<S> {
|
|||
|
||||
impl<S> Peer<S>
|
||||
where
|
||||
S: ReadStorage + WriteStorage,
|
||||
S: ReadStorage + WriteStorage + 'static,
|
||||
{
|
||||
pub fn new(name: &'static str, ip: impl Into<net::IpAddr>, storage: S) -> Self {
|
||||
Self::config(
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
use std::net;
|
||||
|
||||
use crate::identity::ProjId;
|
||||
use crate::storage::{Error, Inventory, ReadStorage, Remotes, Unverified, WriteStorage};
|
||||
|
||||
|
|
@ -40,7 +38,7 @@ impl ReadStorage for MockStorage {
|
|||
}
|
||||
|
||||
impl WriteStorage for MockStorage {
|
||||
fn fetch(&mut self, _proj: &ProjId, _remote: &net::SocketAddr) -> Result<(), Error> {
|
||||
fn repository(&mut self) -> &mut git2::Repository {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue