From 6f706cd32f2c77cec71591ce1ec35ebeec5311df Mon Sep 17 00:00:00 2001 From: HouXiaoxuan Date: Sat, 16 Dec 2023 21:40:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E4=B8=80=E4=BA=9B=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/objects/blob.rs | 5 ++++- src/objects/commit.rs | 15 +++++++++++++++ src/objects/tree.rs | 17 +++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/objects/blob.rs b/src/objects/blob.rs index ed3dcaa..277bd4e 100644 --- a/src/objects/blob.rs +++ b/src/objects/blob.rs @@ -1,6 +1,9 @@ use crate::objects::object::Hash; +/*Blob +* Blob是git中最基本的对象,他储存一份文件的内容,并使用hash作为标识符。 +*/ #[derive(Debug, Clone)] pub struct Blob { hash: Hash, data: String, -} \ No newline at end of file +} diff --git a/src/objects/commit.rs b/src/objects/commit.rs index e69de29..eb2686f 100644 --- a/src/objects/commit.rs +++ b/src/objects/commit.rs @@ -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, // parents commit hash + tree: String, // tree hash +} diff --git a/src/objects/tree.rs b/src/objects/tree.rs index e69de29..b67cf25 100644 --- a/src/objects/tree.rs +++ b/src/objects/tree.rs @@ -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, +}