commits: add a trait to describe storage backend and use-cases

Summary: This will be used to describe what the commit graph backend is.

Reviewed By: sfilipco

Differential Revision: D22970577

fbshipit-source-id: 753efdbdd4466730ece758d9f4789fbd21e2801b
This commit is contained in:
Jun Wu 2020-08-19 15:33:57 -07:00 committed by Jun Wu
parent b77355ca0c
commit d047f07b70
5 changed files with 114 additions and 3 deletions

View File

@ -6,6 +6,7 @@
*/
use crate::AppendCommits;
use crate::DescribeBackend;
use crate::HgCommit;
use crate::HgCommits;
use crate::ReadCommitText;
@ -165,3 +166,31 @@ impl ToSet for DoubleWriteCommits {
self.commits.to_set(set)
}
}
impl DescribeBackend for DoubleWriteCommits {
fn algorithm_backend(&self) -> &'static str {
"segments"
}
fn describe_backend(&self) -> String {
format!(
r#"Backend (doublewrite):
Local:
Segments + IdMap: {}
Zstore: {}
Revlog + Nodemap: {}
Feature Providers:
Commit Graph Algorithms:
Segments
Commit Hash / Rev Lookup:
IdMap
Commit Data (user, message):
Zstore (incomplete)
Revlog
"#,
self.commits.dag_path.display(),
self.commits.commits_path.display(),
self.revlog.dir.join("00changelog.{i,d,nodemap}").display(),
)
}
}

View File

@ -7,6 +7,7 @@
use crate::strip;
use crate::AppendCommits;
use crate::DescribeBackend;
use crate::HgCommit;
use crate::ReadCommitText;
use crate::StripCommits;
@ -37,9 +38,9 @@ use zstore::Zstore;
/// Commits using the HG SHA1 hash function. Stored on disk.
pub struct HgCommits {
commits: Zstore,
commits_path: PathBuf,
pub(crate) commits_path: PathBuf,
dag: Dag,
dag_path: PathBuf,
pub(crate) dag_path: PathBuf,
}
impl HgCommits {
@ -238,3 +239,28 @@ impl ToSet for HgCommits {
self.dag.to_set(set)
}
}
impl DescribeBackend for HgCommits {
fn algorithm_backend(&self) -> &'static str {
"segments"
}
fn describe_backend(&self) -> String {
format!(
r#"Backend (non-lazy segments):
Local:
Segments + IdMap: {}
Zstore: {}
Feature Providers:
Commit Graph Algorithms:
Segments
Commit Hash / Rev Lookup:
IdMap
Commit Data (user, message):
Zstore
"#,
self.dag_path.display(),
self.commits_path.display()
)
}
}

View File

@ -28,6 +28,14 @@ pub trait AppendCommits {
fn flush(&mut self, master_heads: &[Vertex]) -> Result<()>;
}
pub trait DescribeBackend {
/// Name of the DagAlgorithm backend.
fn algorithm_backend(&self) -> &'static str;
/// Describe what storage backend is being used.
fn describe_backend(&self) -> String;
}
/// Parameter used by `add_commits`.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct HgCommit {

View File

@ -7,6 +7,7 @@
use crate::strip;
use crate::AppendCommits;
use crate::DescribeBackend;
use crate::HgCommit;
use crate::ReadCommitText;
use crate::StripCommits;
@ -189,3 +190,24 @@ impl ToSet for MemHgCommits {
self.dag.to_set(set)
}
}
impl DescribeBackend for MemHgCommits {
fn algorithm_backend(&self) -> &'static str {
"segments"
}
fn describe_backend(&self) -> String {
r#"Backend (memory):
Local:
Memory
Feature Providers:
Commit Graph Algorithms:
Memory
Commit Hash / Rev Lookup:
Memory
Commit Data (user, message):
Memory
"#
.to_string()
}
}

View File

@ -7,6 +7,7 @@
use crate::strip;
use crate::AppendCommits;
use crate::DescribeBackend;
use crate::HgCommit;
use crate::ReadCommitText;
use crate::StripCommits;
@ -30,7 +31,7 @@ use std::path::PathBuf;
/// HG commits stored on disk using the revlog format.
pub struct RevlogCommits {
revlog: RevlogIndex,
dir: PathBuf,
pub(crate) dir: PathBuf,
}
impl RevlogCommits {
@ -179,3 +180,28 @@ impl ToSet for RevlogCommits {
self.revlog.to_set(set)
}
}
impl DescribeBackend for RevlogCommits {
fn algorithm_backend(&self) -> &'static str {
"revlog"
}
fn describe_backend(&self) -> String {
format!(
r#"Backend (revlog):
Local:
Revlog: {}
Nodemap: {}
Feature Providers:
Commit Graph Algorithms:
Revlog
Commit Hash / Rev Lookup:
Nodemap
Commit Data (user, message):
Revlog
"#,
self.dir.join("00changelog.{i,d}").display(),
self.dir.join("00changelog.nodemap").display(),
)
}
}