From 2ca52f68cb4f156e2a04915e59db68ee3087bc4d Mon Sep 17 00:00:00 2001 From: Matt Ferraro Date: Thu, 11 Apr 2024 23:13:34 -0400 Subject: [PATCH] clean up example code --- packages/cadmium/src/main.rs | 10 ++-------- packages/cadmium/src/oplog/mod.rs | 33 ++++++++++++++++--------------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/packages/cadmium/src/main.rs b/packages/cadmium/src/main.rs index f6da1622..fa2be08a 100644 --- a/packages/cadmium/src/main.rs +++ b/packages/cadmium/src/main.rs @@ -33,10 +33,6 @@ fn main() { plane_id: top_plane_id.clone(), plane: Plane::top(), }); - let set_name = el.append(Operation::SetPlaneName { - plane_id: top_plane_id.clone(), - name: "Top2".to_string(), - }); let new_extrusion = el.append(Operation::CreateExtrusion { nonce: "b".to_string(), }); @@ -44,18 +40,16 @@ fn main() { extrusion_id: new_extrusion.clone(), name: "Extrusion1".to_string(), }); + + // Rewind to an earlier commit el.checkout(top_plane_id.clone()); el.append(Operation::SetPlaneName { plane_id: top_plane_id.clone(), name: "Bottom".to_string(), }); el.cherry_pick(set_plane); - el.cherry_pick(set_name); el.cherry_pick(new_extrusion); el.cherry_pick(set_ext_name); - // let new_extrusion = el.append(Operation::CreateExtrusion { - // nonce: "c".to_string(), - // }); el.git_log() } diff --git a/packages/cadmium/src/oplog/mod.rs b/packages/cadmium/src/oplog/mod.rs index 55d2e529..b73b3880 100644 --- a/packages/cadmium/src/oplog/mod.rs +++ b/packages/cadmium/src/oplog/mod.rs @@ -251,7 +251,7 @@ impl Commit { impl std::fmt::Display for Commit { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{}: {}", &self.id[..8], self.operation) + write!(f, "{}: {}", &self.id[..6], self.operation) } } @@ -418,6 +418,7 @@ impl Operation { } pub fn pretty_print(&self) -> String { + let num_chars = 6; match self { Operation::Create { nonce } => format!("Create: {}", nonce), Operation::Describe { @@ -425,28 +426,28 @@ impl Operation { commit, } => format!( "Describe: {} '{}'", - commit.to_owned()[..10].to_string(), + commit.to_owned()[..num_chars].to_string(), description ), Operation::Alias { original, new } => { format!( "Alias: from {} to {}", - original.to_owned()[..10].to_string(), - new.to_owned()[..10].to_string() + original.to_owned()[..num_chars].to_string(), + new.to_owned()[..num_chars].to_string() ) } Operation::CreatePlane { nonce } => format!("CreatePlane: {}", nonce), Operation::SetPlaneName { plane_id, name } => { format!( "SetPlaneName: {} '{}'", - plane_id.to_owned()[..10].to_string(), + plane_id.to_owned()[..num_chars].to_string(), name ) } Operation::SetPlane { plane_id, plane } => { format!( "SetPlane: {}", - plane_id.to_owned()[..10].to_string(), + plane_id.to_owned()[..num_chars].to_string(), // plane ) } @@ -454,7 +455,7 @@ impl Operation { Operation::SetSketchName { sketch_id, name } => { format!( "SetSketchName: {} '{}'", - sketch_id.to_owned()[..10].to_string(), + sketch_id.to_owned()[..num_chars].to_string(), name ) } @@ -464,8 +465,8 @@ impl Operation { } => { format!( "SetSketchPlane: {} {}", - sketch_id.to_owned()[..10].to_string(), - plane_id.to_owned()[..10].to_string() + sketch_id.to_owned()[..num_chars].to_string(), + plane_id.to_owned()[..num_chars].to_string() ) } Operation::AddSketchRectangle { @@ -476,7 +477,7 @@ impl Operation { height, } => format!( "AddSketchRectangle: {} ({}, {}) {}x{}", - sketch_id.to_owned()[..10].to_string(), + sketch_id.to_owned()[..num_chars].to_string(), x, y, width, @@ -489,7 +490,7 @@ impl Operation { radius, } => format!( "AddSketchCircle: {} ({}, {}) r={}", - sketch_id.to_owned()[..10].to_string(), + sketch_id.to_owned()[..num_chars].to_string(), x, y, radius @@ -498,7 +499,7 @@ impl Operation { Operation::SetExtrusionName { extrusion_id, name } => { format!( "SetExtrusionName: {} '{}'", - extrusion_id.to_owned()[..10].to_string(), + extrusion_id.to_owned()[..num_chars].to_string(), name ) } @@ -508,8 +509,8 @@ impl Operation { } => { format!( "SetExtrusionSketch: {} {}", - extrusion_id.to_owned()[..10].to_string(), - sketch_id.to_owned()[..10].to_string() + extrusion_id.to_owned()[..num_chars].to_string(), + sketch_id.to_owned()[..num_chars].to_string() ) } Operation::SetExtrusionClicks { @@ -522,7 +523,7 @@ impl Operation { } format!( "SetExtrusionClicks: {} {}", - extrusion_id.to_owned()[..10].to_string(), + extrusion_id.to_owned()[..num_chars].to_string(), click_str ) } @@ -532,7 +533,7 @@ impl Operation { } => { format!( "SetExtrusionDepth: {} {}", - extrusion_id.to_owned()[..10].to_string(), + extrusion_id.to_owned()[..num_chars].to_string(), depth ) }