Skip to content

Commit 5ea49c8

Browse files
committed
[clone] link up lean plumbing command with gitoxide-core: pack-receive
1 parent 40a6412 commit 5ea49c8

File tree

7 files changed

+93
-3
lines changed

7 files changed

+93
-3
lines changed

Diff for: Cargo.lock

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: git-protocol/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "git-protocol"
3-
version = "0.0.0"
3+
version = "0.1.0"
44
repository = "https://github.com/Byron/git-oxide"
55
license = "MIT/Apache-2.0"
66
description = "A WIP crate of the gitoxide project for implementing git protocols"

Diff for: gitoxide-core/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ doctest = false
1212
test = false
1313

1414
[features]
15-
serde1 = ["git-object/serde1", "git-odb/serde1", "serde_json"]
15+
serde1 = ["git-object/serde1", "git-odb/serde1", "git-protocol/serde1", "serde_json"]
1616

1717
[package.metadata.docs.rs]
1818
all-features = true
@@ -21,6 +21,7 @@ all-features = true
2121
git-repository = { version = "0.3.0", path = "../git-repository" }
2222
git-object = { version = "^0.3.0", path = "../git-object" }
2323
git-odb = { version = "0.3.0", path = "../git-odb" }
24+
git-protocol = { version = "0.1.0", path = "../git-protocol" }
2425
git-features = { version = "^0.3.0", path = "../git-features" }
2526
anyhow = "1.0.31"
2627
quick-error = "2.0.0"

Diff for: gitoxide-core/src/pack/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
pub mod explode;
22
pub mod index;
33
pub mod verify;
4+
5+
pub mod receive;
6+
pub use receive::receive;

Diff for: gitoxide-core/src/pack/receive.rs

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use crate::OutputFormat;
2+
use git_features::progress::Progress;
3+
use std::{io, path::PathBuf, str::FromStr};
4+
5+
#[derive(PartialEq, Debug)]
6+
pub enum Protocol {
7+
V1,
8+
V2,
9+
}
10+
11+
impl FromStr for Protocol {
12+
type Err = String;
13+
14+
fn from_str(s: &str) -> Result<Self, Self::Err> {
15+
Ok(match s {
16+
"1" => Protocol::V1,
17+
"2" => Protocol::V2,
18+
_ => return Err(format!("Unsupported protocol version '{}', choose '1' or '2'", s)),
19+
})
20+
}
21+
}
22+
23+
pub struct Context<W: io::Write> {
24+
pub thread_limit: Option<usize>,
25+
pub format: OutputFormat,
26+
pub out: W,
27+
}
28+
29+
pub fn receive<P, W: io::Write>(
30+
_protocol: Option<Protocol>,
31+
_url: &str,
32+
_directory: Option<PathBuf>,
33+
_progress: P,
34+
_ctx: Context<W>,
35+
) -> anyhow::Result<()>
36+
where
37+
P: Progress,
38+
<P as Progress>::SubProgress: Send + 'static,
39+
<<P as Progress>::SubProgress as Progress>::SubProgress: Send,
40+
{
41+
unimplemented!("pack-receive")
42+
}

Diff for: src/plumbing/lean/mod.rs

+18
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,24 @@ pub fn main() -> Result<()> {
3838
let thread_limit = cli.threads;
3939
let verbose = cli.verbose;
4040
match cli.subcommand {
41+
SubCommands::PackReceive(PackReceive {
42+
protocol,
43+
url,
44+
directory,
45+
}) => {
46+
let (_handle, progress) = prepare(verbose, "pack-receive", None);
47+
core::pack::receive(
48+
protocol,
49+
&url,
50+
directory,
51+
progress::DoOrDiscard::from(progress),
52+
core::pack::receive::Context {
53+
thread_limit,
54+
format: OutputFormat::Human,
55+
out: io::stdout(),
56+
},
57+
)
58+
}
4159
SubCommands::IndexFromPack(IndexFromPack {
4260
iteration_mode,
4361
pack_path,

Diff for: src/plumbing/lean/options.rs

+25
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub enum SubCommands {
3030
PackVerify(PackVerify),
3131
PackExplode(PackExplode),
3232
IndexFromPack(IndexFromPack),
33+
PackReceive(PackReceive),
3334
}
3435

3536
/// Create an index from a packfile.
@@ -61,6 +62,30 @@ pub struct IndexFromPack {
6162
pub directory: Option<PathBuf>,
6263
}
6364

65+
/// Receive a pack from a remote identified by a url.
66+
///
67+
/// This is the plumbing equivalent of `git clone` and `git-fetch`.
68+
/// Supported URLs are documented here: https://www.git-scm.com/docs/git-clone#_git_urls
69+
#[derive(FromArgs, PartialEq, Debug)]
70+
#[argh(subcommand, name = "pack-receive")]
71+
pub struct PackReceive {
72+
/// the protocol version to use. Valid values are 1 and 2
73+
#[argh(option)]
74+
pub protocol: Option<core::pack::receive::Protocol>,
75+
76+
/// the URLs or path from which to receive the pack.
77+
///
78+
/// See here for a list of supported URLs: https://www.git-scm.com/docs/git-clone#_git_urls
79+
#[argh(positional)]
80+
pub url: String,
81+
82+
/// the directory into which to write the received pack and index.
83+
///
84+
/// If unset, they will be discarded.
85+
#[argh(positional)]
86+
pub directory: Option<PathBuf>,
87+
}
88+
6489
/// Explode a pack into loose objects.
6590
///
6691
/// This can be useful in case of partially invalidated packs to extract as much information as possible,

0 commit comments

Comments
 (0)