checkout: impl Display for CheckoutPlan

Summary: Also add __str__ Python binding. Usefull for debugging

Reviewed By: quark-zju

Differential Revision: D26496791

fbshipit-source-id: 8bcfc89918c5fafc9ac8e42ef91c576b160d943c
This commit is contained in:
Andrey Chursin 2021-02-19 10:27:15 -08:00 committed by Facebook GitHub Bot
parent de6e57e067
commit c7269df47e
2 changed files with 31 additions and 0 deletions

View File

@ -59,4 +59,13 @@ py_class!(class checkoutplan |py| {
Ok(PyNone)
}
def __str__(&self) -> PyResult<PyString> {
if let Some(plan) = self.plan(py).borrow().as_ref() {
Ok(PyString::new(py, &plan.to_string()))
} else {
// Not returning error since ideally __str_ should not fail
Ok(PyString::new(py, "checkoutplan was already applied"))
}
}
});

View File

@ -9,6 +9,7 @@ use anyhow::{bail, format_err, Result};
use futures::{stream, try_join, Stream, StreamExt};
use manifest::{DiffEntry, DiffType, FileMetadata, FileType};
use revisionstore::{HgIdDataStore, RemoteDataStore, StoreKey, StoreResult};
use std::fmt;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use types::{HgId, Key, RepoPathBuf};
@ -551,3 +552,24 @@ mod test {
hgid.to_string().into_bytes()
}
}
impl fmt::Display for CheckoutPlan {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for r in &self.remove {
writeln!(f, "rm {}", r)?;
}
for u in &self.update_content {
let ft = match u.file_type {
FileType::Executable => "(x)",
FileType::Symlink => "(s)",
FileType::Regular => "",
};
writeln!(f, "up {}=>{}{}", u.path, u.content_hgid, ft)?;
}
for u in &self.update_meta {
let ch = if u.set_x_flag { "+x" } else { "-x" };
writeln!(f, "{} {}", ch, u.path)?;
}
Ok(())
}
}