Skip to content

Commit

Permalink
[clone] link up lean plumbing command with gitoxide-core: pack-receive
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 18, 2020
1 parent 40a6412 commit 5ea49c8
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion git-protocol/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "git-protocol"
version = "0.0.0"
version = "0.1.0"
repository = "https://github.com/Byron/git-oxide"
license = "MIT/Apache-2.0"
description = "A WIP crate of the gitoxide project for implementing git protocols"
Expand Down
3 changes: 2 additions & 1 deletion gitoxide-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ doctest = false
test = false

[features]
serde1 = ["git-object/serde1", "git-odb/serde1", "serde_json"]
serde1 = ["git-object/serde1", "git-odb/serde1", "git-protocol/serde1", "serde_json"]

[package.metadata.docs.rs]
all-features = true
Expand All @@ -21,6 +21,7 @@ all-features = true
git-repository = { version = "0.3.0", path = "../git-repository" }
git-object = { version = "^0.3.0", path = "../git-object" }
git-odb = { version = "0.3.0", path = "../git-odb" }
git-protocol = { version = "0.1.0", path = "../git-protocol" }
git-features = { version = "^0.3.0", path = "../git-features" }
anyhow = "1.0.31"
quick-error = "2.0.0"
Expand Down
3 changes: 3 additions & 0 deletions gitoxide-core/src/pack/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
pub mod explode;
pub mod index;
pub mod verify;

pub mod receive;
pub use receive::receive;
42 changes: 42 additions & 0 deletions gitoxide-core/src/pack/receive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use crate::OutputFormat;
use git_features::progress::Progress;
use std::{io, path::PathBuf, str::FromStr};

#[derive(PartialEq, Debug)]
pub enum Protocol {
V1,
V2,
}

impl FromStr for Protocol {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"1" => Protocol::V1,
"2" => Protocol::V2,
_ => return Err(format!("Unsupported protocol version '{}', choose '1' or '2'", s)),
})
}
}

pub struct Context<W: io::Write> {
pub thread_limit: Option<usize>,
pub format: OutputFormat,
pub out: W,
}

pub fn receive<P, W: io::Write>(
_protocol: Option<Protocol>,
_url: &str,
_directory: Option<PathBuf>,
_progress: P,
_ctx: Context<W>,
) -> anyhow::Result<()>
where
P: Progress,
<P as Progress>::SubProgress: Send + 'static,
<<P as Progress>::SubProgress as Progress>::SubProgress: Send,
{
unimplemented!("pack-receive")
}
18 changes: 18 additions & 0 deletions src/plumbing/lean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ pub fn main() -> Result<()> {
let thread_limit = cli.threads;
let verbose = cli.verbose;
match cli.subcommand {
SubCommands::PackReceive(PackReceive {
protocol,
url,
directory,
}) => {
let (_handle, progress) = prepare(verbose, "pack-receive", None);
core::pack::receive(
protocol,
&url,
directory,
progress::DoOrDiscard::from(progress),
core::pack::receive::Context {
thread_limit,
format: OutputFormat::Human,
out: io::stdout(),
},
)
}
SubCommands::IndexFromPack(IndexFromPack {
iteration_mode,
pack_path,
Expand Down
25 changes: 25 additions & 0 deletions src/plumbing/lean/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub enum SubCommands {
PackVerify(PackVerify),
PackExplode(PackExplode),
IndexFromPack(IndexFromPack),
PackReceive(PackReceive),
}

/// Create an index from a packfile.
Expand Down Expand Up @@ -61,6 +62,30 @@ pub struct IndexFromPack {
pub directory: Option<PathBuf>,
}

/// Receive a pack from a remote identified by a url.
///
/// This is the plumbing equivalent of `git clone` and `git-fetch`.
/// Supported URLs are documented here: https://www.git-scm.com/docs/git-clone#_git_urls
#[derive(FromArgs, PartialEq, Debug)]
#[argh(subcommand, name = "pack-receive")]
pub struct PackReceive {
/// the protocol version to use. Valid values are 1 and 2
#[argh(option)]
pub protocol: Option<core::pack::receive::Protocol>,

/// the URLs or path from which to receive the pack.
///
/// See here for a list of supported URLs: https://www.git-scm.com/docs/git-clone#_git_urls
#[argh(positional)]
pub url: String,

/// the directory into which to write the received pack and index.
///
/// If unset, they will be discarded.
#[argh(positional)]
pub directory: Option<PathBuf>,
}

/// Explode a pack into loose objects.
///
/// This can be useful in case of partially invalidated packs to extract as much information as possible,
Expand Down

0 comments on commit 5ea49c8

Please sign in to comment.