实现一些数据结构

This commit is contained in:
HouXiaoxuan
2023-12-16 21:40:35 +08:00
parent 2df0375e2e
commit 6f706cd32f
3 changed files with 36 additions and 1 deletions

View File

@@ -1,6 +1,9 @@
use crate::objects::object::Hash;
/*Blob
* Blob是git中最基本的对象他储存一份文件的内容并使用hash作为标识符。
*/
#[derive(Debug, Clone)]
pub struct Blob {
hash: Hash,
data: String,
}
}

View File

@@ -0,0 +1,15 @@
use super::object::Hash;
/*Commit
* git中版本控制的单位。
* 一份Commit中对应一份版Tree记录了该版本所包含的文件parent记录本次commit的来源形成了版本树
* 此外Commit中还包含了作者、提交者、提交信息等。
*/
#[derive(Debug, Clone)]
pub struct Commit {
hash: Hash,
author: String, // unimplemented ignore
committer: String, // unimplemented ignore
message: String,
parent: Vec<Hash>, // parents commit hash
tree: String, // tree hash
}

View File

@@ -0,0 +1,17 @@
use super::object::Hash;
/*Tree
* Tree是一个版本中所有文件的集合。从根目录还是每个目录是一个Tree每个文件是一个Blob。Tree之间互相嵌套表示文件的层级关系。
* 每一个Tree对象也是对应到git储存仓库的一个文件其内容是一个或多个TreeEntry。
*/
#[derive(Debug, Clone)]
pub struct TreeEntry {
pub filemode: (String, String), // (type, mode), type: blob or tree; mode: 100644 or 04000
pub hash: Hash, // blob hash or tree hash
pub name: String, // file name
}
#[derive(Debug, Clone)]
pub struct Tree {
pub hash: Hash,
pub entries: Vec<TreeEntry>,
}