Fix log and add to example.sh / example_output

`status` bug remains
This commit is contained in:
Josh Hansen 2023-09-28 14:50:38 -07:00
parent 9d2650d0a5
commit da30513add
3 changed files with 45 additions and 13 deletions

View file

@ -86,6 +86,8 @@ main() {
btrfs() {
$GHEE status .
$GHEE log
$GHEE create -v -k toppings ./pizza
$GHEE status ./pizza
@ -96,6 +98,8 @@ btrfs() {
$GHEE commit -m "Add olive pizza" ./pizza
$GHEE log ./pizza
$GHEE status ./pizza
$GHEE touch ./pizza/pepperoni
@ -110,6 +114,8 @@ btrfs() {
$GHEE status ./pizza
$GHEE log ./pizza
cd pizza
$GHEE touch buffalo-chicken

View file

@ -170,6 +170,8 @@ No table found
+ btrfs
+ /home/josh/Projects/Ghee/target/debug/ghee status .
No table found
+ /home/josh/Projects/Ghee/target/debug/ghee log
No table found; no log exists
+ /home/josh/Projects/Ghee/target/debug/ghee create -v -k toppings ./pizza
Initialized table ./pizza with key: user.toppings
+ /home/josh/Projects/Ghee/target/debug/ghee status ./pizza
@ -179,6 +181,11 @@ Initialized table ./pizza with key: user.toppings
+./pizza
+./pizza/olive
+ /home/josh/Projects/Ghee/target/debug/ghee commit -m Add olive pizza ./pizza
+ /home/josh/Projects/Ghee/target/debug/ghee log ./pizza
commit dffea10f-ff92-9c41-98c4-66316e245ea9
Add olive pizza
+ /home/josh/Projects/Ghee/target/debug/ghee status ./pizza
+ /home/josh/Projects/Ghee/target/debug/ghee touch ./pizza/pepperoni
+ echo Olives are good on pizza
@ -188,6 +195,15 @@ m./pizza/olive
+./pizza/pepperoni
+ /home/josh/Projects/Ghee/target/debug/ghee commit -m Add pepperoni; add details to olive ./pizza
+ /home/josh/Projects/Ghee/target/debug/ghee status ./pizza
+ /home/josh/Projects/Ghee/target/debug/ghee log ./pizza
commit 92e92c38-e362-a54a-8bd2-eebad3aca3c4
Add pepperoni; add details to olive
commit dffea10f-ff92-9c41-98c4-66316e245ea9
Add olive pizza
+ cd ..
+ sudo umount ./btrfs
+ cd ..

View file

@ -3,29 +3,39 @@ use std::path::PathBuf;
use anyhow::Result;
use colored::Colorize;
use ghee_lang::Value;
use xattr;
use crate::{
paths::table_snapshot_path, xattr_value, XATTR_MOST_RECENT_SNAPSHOT, XATTR_SNAPSHOT_MESSAGE,
containing_table_info, paths::table_snapshot_path, xattr_value, XATTR_MOST_RECENT_SNAPSHOT,
XATTR_SNAPSHOT_MESSAGE,
};
pub fn log(dir: &PathBuf) -> Result<()> {
if xattr::get(dir, XATTR_MOST_RECENT_SNAPSHOT.to_osstring()).is_ok() {
let mut snapshot_path = dir.clone();
if let Some(info) = containing_table_info(dir)? {
let table_path = info.path_abs();
while let Ok(most_recent_snapshot) =
xattr_value(&snapshot_path, &XATTR_MOST_RECENT_SNAPSHOT)
if let Ok(mut most_recent_snapshot) = xattr_value(&table_path, &XATTR_MOST_RECENT_SNAPSHOT)
{
let commit = format!("commit {}", most_recent_snapshot).yellow();
println!("{}", commit);
let message = xattr_value(&snapshot_path, &XATTR_SNAPSHOT_MESSAGE)
.unwrap_or(Value::String("--No message--".to_string()));
println!("\n\t{}\n", message);
let mut snapshot_path = Some(table_snapshot_path(table_path, &most_recent_snapshot));
snapshot_path = table_snapshot_path(&dir, most_recent_snapshot);
while let Some(sp) = snapshot_path.take() {
let commit = format!("commit {}", most_recent_snapshot).yellow();
println!("{}", commit);
let message = xattr_value(&sp, &XATTR_SNAPSHOT_MESSAGE)
.unwrap_or(Value::String("--No message--".to_string()));
println!("\n\t{}\n", message);
if let Ok(less_recent_snapshot) = xattr_value(&sp, &XATTR_MOST_RECENT_SNAPSHOT) {
snapshot_path = Some(table_snapshot_path(table_path, &less_recent_snapshot));
most_recent_snapshot = less_recent_snapshot;
} else {
snapshot_path = None;
}
}
} else {
println!("No commit log exists; use `commit` to commit changes");
}
} else {
println!("No commit log exists; use `commit` to commit changes");
println!("No table found; no log exists");
}
Ok(())