summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs68
1 files changed, 51 insertions, 17 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 7f6b86f..b7994d3 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -6,13 +6,21 @@ use std::fs::{File, Metadata};
use std::path::{Path, PathBuf};
use std::time::Instant;
+use serde::{Deserialize, Serialize};
+
+mod object;
mod workarea;
+#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
struct ContributorId(String);
+#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
struct ChannelId(String);
+#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
struct PatchId(String);
+#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
struct FileId(String);
-struct SpanId(String);
+#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
+struct SpanNodeId(String);
struct Remote {
url: String,
@@ -35,34 +43,46 @@ struct Channel {
patches: Vec<PatchId>,
}
+#[derive(Debug, Clone, Deserialize, Serialize)]
struct Patch {
id: PatchId,
authors: Vec<ContributorId>,
recorder: ContributorId,
metadata: HashMap<String, String>,
- added_spans: Vec<SpanId>,
- deleted_spans: Vec<SpanId>,
- added_files: Vec<FileId>,
- deleted_files: Vec<FileId>,
+ affected_files: Vec<FileId>,
+ contents: String,
}
+#[derive(Debug, Clone, Deserialize, Serialize)]
struct FileInfo {
id: FileId,
- inode: Option<u64>,
- spans: Vec<SpanId>,
+ root_span: SpanNodeId,
+ name_changes: Vec<(PatchId, FilenameOperation)>,
+ spans: Vec<SpanNode>,
+}
+
+#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
+enum FilenameOperation {
+ Add { filename: PathBuf },
+ Rename { filename: PathBuf },
+ Delete,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+struct SpanNode {
+ id: SpanNodeId,
+ span: Span,
added_by: Vec<PatchId>,
- renamed_by: Vec<(PatchId, PathBuf)>,
deleted_by: Vec<PatchId>,
+ preceding_nodes: Vec<SpanNodeId>,
+ successor_nodes: Vec<SpanNodeId>,
}
+#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
struct Span {
- id: SpanId,
- file: FileId,
- after: Vec<SpanId>,
- before: Vec<SpanId>,
- contents: Vec<u8>,
- added_by: Vec<PatchId>,
- deleted_by: Vec<PatchId>,
+ patch: PatchId,
+ start: usize,
+ len: usize,
}
type DiffAlgorithm = fn(File, File) -> Diff;
@@ -84,6 +104,22 @@ enum LogEntry {
type RevertAlgorithm = fn(Patch) -> Patch;
+trait Id {
+ fn id(&self) -> &str;
+}
+
+impl Id for Patch {
+ fn id(&self) -> &str {
+ &self.id.0
+ }
+}
+
+impl Id for FileInfo {
+ fn id(&self) -> &str {
+ &self.id.0
+ }
+}
+
trait StagingArea {
fn list_files() -> std::io::Result<Metadata>;
fn open_file(path: &Path) -> std::io::Result<File>;
@@ -127,6 +163,4 @@ trait Repository {
fn active_files(&self) -> Vec<FileId>;
fn file(&self, id: FileId) -> Option<FileInfo>;
fn write_file_from_patch(&self, id: FileId, patch: PatchId) -> Vec<u8>;
-
- fn span(&self, id: SpanId) -> Option<Span>;
}