From d3da261c32f1be6825832ea0ae113a3e6c140df7 Mon Sep 17 00:00:00 2001 From: Muir Manders Date: Tue, 2 Nov 2021 14:32:21 -0700 Subject: [PATCH] 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 --- .../bindings/modules/pyprogress/Cargo.toml | 1 - eden/scm/lib/progress/Cargo.toml | 8 -- eden/scm/lib/progress/src/lib.rs | 78 --------------- eden/scm/lib/progress/src/null.rs | 95 ------------------- 4 files changed, 182 deletions(-) delete mode 100644 eden/scm/lib/progress/Cargo.toml delete mode 100644 eden/scm/lib/progress/src/lib.rs delete mode 100644 eden/scm/lib/progress/src/null.rs diff --git a/eden/scm/edenscmnative/bindings/modules/pyprogress/Cargo.toml b/eden/scm/edenscmnative/bindings/modules/pyprogress/Cargo.toml index 366c42e0db..80a072f21d 100644 --- a/eden/scm/edenscmnative/bindings/modules/pyprogress/Cargo.toml +++ b/eden/scm/edenscmnative/bindings/modules/pyprogress/Cargo.toml @@ -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" } diff --git a/eden/scm/lib/progress/Cargo.toml b/eden/scm/lib/progress/Cargo.toml deleted file mode 100644 index 78d1aa6874..0000000000 --- a/eden/scm/lib/progress/Cargo.toml +++ /dev/null @@ -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" diff --git a/eden/scm/lib/progress/src/lib.rs b/eden/scm/lib/progress/src/lib.rs deleted file mode 100644 index 895335d4d4..0000000000 --- a/eden/scm/lib/progress/src/lib.rs +++ /dev/null @@ -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, unit: Unit) -> Result>; - - /// Start a progress spinner. - fn spinner(&self, message: &str) -> Result>; -} - -/// 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; - - /// Get the total length of the progress bar. - fn total(&self) -> Result>; - - /// 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) -> 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), - } - } -} diff --git a/eden/scm/lib/progress/src/null.rs b/eden/scm/lib/progress/src/null.rs deleted file mode 100644 index 2a22861ffb..0000000000 --- a/eden/scm/lib/progress/src/null.rs +++ /dev/null @@ -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 { - Arc::new(NullProgressFactory) - } -} - -impl ProgressFactory for NullProgressFactory { - fn bar(&self, _message: &str, total: Option, _unit: Unit) -> Result> { - Ok(Box::new(NullProgressBar::new(total))) - } - - fn spinner(&self, _message: &str) -> Result> { - Ok(Box::new(NullProgressSpinner)) - } -} - -#[derive(Default)] -struct NullProgressBar { - position: AtomicU64, - total: AtomicU64, -} - -impl NullProgressBar { - fn new(total: Option) -> 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 { - Ok(self.position.load(Ordering::Relaxed)) - } - - fn total(&self) -> Result> { - 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) -> 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(()) - } -}