progress: remove "progress" crate

Summary: This has been superseded by a simple concrete rust progress bar implementation in the progress-model crate.

Reviewed By: andll

Differential Revision: D32068068

fbshipit-source-id: 2f27040d8bf8c2089c66ee3e1db9258eb50b51e6
This commit is contained in:
Muir Manders 2021-11-02 14:32:21 -07:00 committed by Facebook GitHub Bot
parent 8a4dd8c5d9
commit d3da261c32
4 changed files with 0 additions and 182 deletions

View File

@ -6,7 +6,6 @@ edition = "2021"
[dependencies]
cpython = { version = "0.5", default-features = false }
cpython_ext = { path = "../../../../lib/cpython-ext", default-features = false }
progress = { path = "../../../../lib/progress" }
progress-model = { path = "../../../../lib/progress/model" }
progress-render = { path = "../../../../lib/progress/render" }

View File

@ -1,8 +0,0 @@
# @generated by autocargo from //eden/scm/lib/progress:progress
[package]
name = "progress"
version = "0.1.0"
edition = "2021"
[dependencies]
anyhow = "1.0"

View File

@ -1,78 +0,0 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
//! progress - A generic interface for representing progress bars.
//!
//! The intention of this crate is to abstract away the implementation details
//! of progress bars from Mercurial's Rust code. This allows pure Rust code to
//! work with Mercurial's Python progress bars, but leaves the door open for
//! a pure Rust progress bar implementation in the future.
use anyhow::Result;
pub use null::NullProgressFactory;
pub mod null;
/// Factory interface for creating progress bars and spinners.
pub trait ProgressFactory: Send + Sync + 'static {
/// Start a progress bar.
fn bar(&self, message: &str, total: Option<u64>, unit: Unit) -> Result<Box<dyn ProgressBar>>;
/// Start a progress spinner.
fn spinner(&self, message: &str) -> Result<Box<dyn ProgressSpinner>>;
}
/// Trait to be implemented by types representing progress bars.
pub trait ProgressBar: Send + Sync + 'static {
/// Get the current position of the progress bar.
fn position(&self) -> Result<u64>;
/// Get the total length of the progress bar.
fn total(&self) -> Result<Option<u64>>;
/// Set the current position of the progress bar.
fn set(&self, pos: u64) -> Result<()>;
/// Change the total length of the progress bar.
fn set_total(&self, total: Option<u64>) -> Result<()>;
/// Increment the current position by the given amount.
fn increment(&self, delta: u64) -> Result<()>;
/// Change the message shown by the progress bar.
fn set_message(&self, message: &str) -> Result<()>;
}
/// Trait to be implemented by types representing progress spinners.
pub trait ProgressSpinner: Send + Sync + 'static {
/// Change the message shown by the spinner.
fn set_message(&self, message: &str) -> Result<()>;
}
/// Unit to display in progress bar's counter.
#[derive(Copy, Clone, Debug)]
pub enum Unit<'a> {
None,
Bytes,
Named(&'a str),
}
impl<'a> Default for Unit<'a> {
fn default() -> Self {
Unit::None
}
}
impl<'a> From<&'a str> for Unit<'a> {
fn from(unit: &'a str) -> Self {
match unit {
"" => Unit::None,
"bytes" => Unit::Bytes,
other => Unit::Named(other),
}
}
}

View File

@ -1,95 +0,0 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
//! No-op progress bar placeholders. Enables code that can optionally report
//! progress to unconditionally update the progress bar rather than using
//! conditionals at every callsite.
use std::sync::atomic::AtomicU64;
use std::sync::atomic::Ordering;
use std::sync::Arc;
use anyhow::Result;
use crate::ProgressBar;
use crate::ProgressFactory;
use crate::ProgressSpinner;
use crate::Unit;
pub struct NullProgressFactory;
impl NullProgressFactory {
pub fn arc() -> Arc<dyn ProgressFactory> {
Arc::new(NullProgressFactory)
}
}
impl ProgressFactory for NullProgressFactory {
fn bar(&self, _message: &str, total: Option<u64>, _unit: Unit) -> Result<Box<dyn ProgressBar>> {
Ok(Box::new(NullProgressBar::new(total)))
}
fn spinner(&self, _message: &str) -> Result<Box<dyn ProgressSpinner>> {
Ok(Box::new(NullProgressSpinner))
}
}
#[derive(Default)]
struct NullProgressBar {
position: AtomicU64,
total: AtomicU64,
}
impl NullProgressBar {
fn new(total: Option<u64>) -> Self {
Self {
position: AtomicU64::new(0),
// XXX: Use 0 to represent None so that we can just use an AtomicU64
// to store the total. This is incorrect for cases where the caller
// actually wants to set the total to 0, but that should be rare.
total: AtomicU64::new(total.unwrap_or(0)),
}
}
}
impl ProgressBar for NullProgressBar {
fn position(&self) -> Result<u64> {
Ok(self.position.load(Ordering::Relaxed))
}
fn total(&self) -> Result<Option<u64>> {
let total = self.total.load(Ordering::Relaxed);
Ok(if total == 0 { None } else { Some(total) })
}
fn set(&self, pos: u64) -> Result<()> {
self.position.store(pos, Ordering::Relaxed);
Ok(())
}
fn set_total(&self, total: Option<u64>) -> Result<()> {
self.total.store(total.unwrap_or(0), Ordering::Relaxed);
Ok(())
}
fn increment(&self, delta: u64) -> Result<()> {
let _ = self.position.fetch_add(delta, Ordering::Relaxed);
Ok(())
}
fn set_message(&self, _message: &str) -> Result<()> {
Ok(())
}
}
struct NullProgressSpinner;
impl ProgressSpinner for NullProgressSpinner {
fn set_message(&self, _message: &str) -> Result<()> {
Ok(())
}
}