-
-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ref-ls] Frame for remote-ref-ls command in gitoxide-core
- Loading branch information
Showing
8 changed files
with
217 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use std::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)), | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
pub mod refs { | ||
use crate::{OutputFormat, Protocol}; | ||
use git_features::progress::Progress; | ||
use std::io; | ||
|
||
pub struct Context<W: io::Write> { | ||
pub thread_limit: Option<usize>, | ||
pub format: OutputFormat, | ||
pub out: W, | ||
} | ||
|
||
pub fn list<P, W: io::Write>( | ||
_protocol: Option<Protocol>, | ||
_url: &str, | ||
_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!("remote ref list") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
use crate::shared::ProgressRange; | ||
use anyhow::Result; | ||
use git_features::progress; | ||
use gitoxide_core::{self as core, OutputFormat}; | ||
use std::io::{self, stderr, stdout}; | ||
|
||
#[cfg(not(any(feature = "prodash-render-line-crossterm", feature = "prodash-render-line-termion")))] | ||
fn prepare(verbose: bool, name: &str, _: impl Into<Option<ProgressRange>>) -> ((), Option<prodash::progress::Log>) { | ||
super::init_env_logger(verbose); | ||
((), Some(prodash::progress::Log::new(name, Some(1)))) | ||
} | ||
|
||
#[cfg(any(feature = "prodash-render-line-crossterm", feature = "prodash-render-line-termion"))] | ||
fn prepare( | ||
verbose: bool, | ||
name: &str, | ||
range: impl Into<Option<ProgressRange>>, | ||
) -> (Option<prodash::render::line::JoinHandle>, Option<prodash::tree::Item>) { | ||
use crate::shared::{self, STANDARD_RANGE}; | ||
crate::plumbing::init_env_logger(false); | ||
|
||
if verbose { | ||
let progress = prodash::Tree::new(); | ||
let sub_progress = progress.add_child(name); | ||
let handle = shared::setup_line_renderer_range(progress, range.into().unwrap_or(STANDARD_RANGE), true); | ||
(Some(handle), Some(sub_progress)) | ||
} else { | ||
(None, None) | ||
} | ||
} | ||
|
||
pub fn main() -> Result<()> { | ||
pub use crate::plumbing::lean::options::*; | ||
let cli: Args = crate::shared::from_env(); | ||
git_features::interrupt::init_handler(std::io::stderr()); | ||
let thread_limit = cli.threads; | ||
let verbose = cli.verbose; | ||
match cli.subcommand { | ||
SubCommands::RemoteRefList(RemoteRefList { protocol, url }) => { | ||
let (_handle, progress) = prepare(verbose, "remote-ref-list", None); | ||
core::remote::refs::list( | ||
protocol, | ||
&url, | ||
progress::DoOrDiscard::from(progress), | ||
core::remote::refs::Context { | ||
thread_limit, | ||
format: OutputFormat::Human, | ||
out: io::stdout(), | ||
}, | ||
) | ||
} | ||
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, | ||
directory, | ||
}) => { | ||
let (_handle, progress) = prepare(verbose, "pack-explode", core::pack::index::PROGRESS_RANGE); | ||
core::pack::index::from_pack( | ||
pack_path, | ||
directory, | ||
progress::DoOrDiscard::from(progress), | ||
core::pack::index::Context { | ||
thread_limit, | ||
iteration_mode: iteration_mode.unwrap_or_default(), | ||
format: OutputFormat::Human, | ||
out: io::stdout(), | ||
}, | ||
) | ||
} | ||
SubCommands::PackExplode(PackExplode { | ||
pack_path, | ||
sink_compress, | ||
object_path, | ||
verify, | ||
check, | ||
delete_pack, | ||
}) => { | ||
let (_handle, progress) = prepare(verbose, "pack-explode", None); | ||
core::pack::explode::pack_or_pack_index( | ||
pack_path, | ||
object_path, | ||
check.unwrap_or_default(), | ||
progress, | ||
core::pack::explode::Context { | ||
thread_limit, | ||
delete_pack, | ||
sink_compress, | ||
verify, | ||
}, | ||
) | ||
} | ||
SubCommands::PackVerify(PackVerify { | ||
path, | ||
statistics, | ||
algorithm, | ||
decode, | ||
re_encode, | ||
}) => { | ||
use self::core::pack::verify; | ||
let (_handle, progress) = prepare(verbose, "pack-verify", None); | ||
core::pack::verify::pack_or_pack_index( | ||
path, | ||
progress, | ||
core::pack::verify::Context { | ||
output_statistics: if statistics { | ||
Some(core::OutputFormat::Human) | ||
} else { | ||
None | ||
}, | ||
algorithm: algorithm.unwrap_or(verify::Algorithm::LessTime), | ||
thread_limit, | ||
mode: match (decode, re_encode) { | ||
(true, false) => verify::Mode::Sha1CRC32Decode, | ||
(true, true) | (false, true) => verify::Mode::Sha1CRC32DecodeEncode, | ||
(false, false) => verify::Mode::Sha1CRC32, | ||
}, | ||
out: stdout(), | ||
err: stderr(), | ||
}, | ||
) | ||
.map(|_| ()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,131 +1,3 @@ | ||
mod main; | ||
pub use main::main; | ||
mod options; | ||
|
||
use crate::shared::ProgressRange; | ||
use anyhow::Result; | ||
use git_features::progress; | ||
use gitoxide_core::{self as core, OutputFormat}; | ||
use std::io::{self, stderr, stdout}; | ||
|
||
#[cfg(not(any(feature = "prodash-render-line-crossterm", feature = "prodash-render-line-termion")))] | ||
fn prepare(verbose: bool, name: &str, _: impl Into<Option<ProgressRange>>) -> ((), Option<prodash::progress::Log>) { | ||
super::init_env_logger(verbose); | ||
((), Some(prodash::progress::Log::new(name, Some(1)))) | ||
} | ||
|
||
#[cfg(any(feature = "prodash-render-line-crossterm", feature = "prodash-render-line-termion"))] | ||
fn prepare( | ||
verbose: bool, | ||
name: &str, | ||
range: impl Into<Option<ProgressRange>>, | ||
) -> (Option<prodash::render::line::JoinHandle>, Option<prodash::tree::Item>) { | ||
use crate::shared::{self, STANDARD_RANGE}; | ||
super::init_env_logger(false); | ||
|
||
if verbose { | ||
let progress = prodash::Tree::new(); | ||
let sub_progress = progress.add_child(name); | ||
let handle = shared::setup_line_renderer_range(progress, range.into().unwrap_or(STANDARD_RANGE), true); | ||
(Some(handle), Some(sub_progress)) | ||
} else { | ||
(None, None) | ||
} | ||
} | ||
|
||
pub fn main() -> Result<()> { | ||
pub use options::*; | ||
let cli: Args = crate::shared::from_env(); | ||
git_features::interrupt::init_handler(std::io::stderr()); | ||
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, | ||
directory, | ||
}) => { | ||
let (_handle, progress) = prepare(verbose, "pack-explode", core::pack::index::PROGRESS_RANGE); | ||
core::pack::index::from_pack( | ||
pack_path, | ||
directory, | ||
progress::DoOrDiscard::from(progress), | ||
core::pack::index::Context { | ||
thread_limit, | ||
iteration_mode: iteration_mode.unwrap_or_default(), | ||
format: OutputFormat::Human, | ||
out: io::stdout(), | ||
}, | ||
) | ||
} | ||
SubCommands::PackExplode(PackExplode { | ||
pack_path, | ||
sink_compress, | ||
object_path, | ||
verify, | ||
check, | ||
delete_pack, | ||
}) => { | ||
let (_handle, progress) = prepare(verbose, "pack-explode", None); | ||
core::pack::explode::pack_or_pack_index( | ||
pack_path, | ||
object_path, | ||
check.unwrap_or_default(), | ||
progress, | ||
core::pack::explode::Context { | ||
thread_limit, | ||
delete_pack, | ||
sink_compress, | ||
verify, | ||
}, | ||
) | ||
} | ||
SubCommands::PackVerify(PackVerify { | ||
path, | ||
statistics, | ||
algorithm, | ||
decode, | ||
re_encode, | ||
}) => { | ||
use self::core::pack::verify; | ||
let (_handle, progress) = prepare(verbose, "pack-verify", None); | ||
core::pack::verify::pack_or_pack_index( | ||
path, | ||
progress, | ||
core::pack::verify::Context { | ||
output_statistics: if statistics { | ||
Some(core::OutputFormat::Human) | ||
} else { | ||
None | ||
}, | ||
algorithm: algorithm.unwrap_or(verify::Algorithm::LessTime), | ||
thread_limit, | ||
mode: match (decode, re_encode) { | ||
(true, false) => verify::Mode::Sha1CRC32Decode, | ||
(true, true) | (false, true) => verify::Mode::Sha1CRC32DecodeEncode, | ||
(false, false) => verify::Mode::Sha1CRC32, | ||
}, | ||
out: stdout(), | ||
err: stderr(), | ||
}, | ||
) | ||
.map(|_| ()) | ||
} | ||
} | ||
} |
Oops, something went wrong.