Skip to content

第二阶段任务解读和疑惑#6

Open
bigbeats wants to merge 4 commits intodev1from
dev_pym
Open

第二阶段任务解读和疑惑#6
bigbeats wants to merge 4 commits intodev1from
dev_pym

Conversation

@bigbeats
Copy link
Copy Markdown
Collaborator

@bigbeats bigbeats commented Dec 10, 2020

该文件用于明确第二阶段任务要做的一些工作。还列出了如下内容:
1.列出具体要实现的任务
2.提出了关于任务的解读
3.列出了一些可能需要在此次任务中实现的方法
4.提出了关于实现gitlog和gitreset方法的疑惑,请见第三部分
@js00070 感谢学长的悉心指导,恳请学长指正!

该文件用于明确第二阶段任务要做的一些工作,并且提出了一些关于实现第二阶段任务的方法解读。
Comment thread 第二阶段任务解读.md Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不会显示的,因为相当于是恢复到指定的commit对应的版本快照了,这个官方的git也是这样,可以试试

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

明白!学长,我也看了一下git的实现,确实不会显示。

get value()方法得到某次commit里的所有信息blob key,tree key,author等等
get diff()方法得到当前commit和某次commit之间哪些文件发生了差异
Comment thread 第二阶段任务解读.md Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的,而且如果你要缓存的话,得每个分支单独都缓存一份git log

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的,而且如果你要缓存的话,得每个分支单独都缓存一份git log

确实,感谢学长的光速解答!!!
学长,我刚刚又增加了get value方法和get diff方法:
get value()方法得到某次commit里的所有信息blob key,tree key,author等等
get diff()方法得到当前commit和某次commit之间哪些文件发生了差异

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的,而且如果你要缓存的话,得每个分支单独都缓存一份git log

确实,感谢学长的光速解答!!!
学长,我刚刚又增加了get value方法和get diff方法:
get value()方法得到某次commit里的所有信息blob key,tree key,author等等
get diff()方法得到当前commit和某次commit之间哪些文件发生了差异

diff这个实现起来比较有难度的,感兴趣的话可以尝试尝试,参考:https://segmentfault.com/p/1210000009610313/read

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

太强了太强了!感谢学长的指点!!!!

@bigbeats bigbeats linked an issue Dec 10, 2020 that may be closed by this pull request
如何实现setprecommitkey()
HEAD文件里只存放当前分支指向的commit,HEAD文件在第一次commit时产生。
commit类里有个私有成员域是precommit,有个setprecommit()方法【方法体就是读当前HEAD文件里那一条commit并附给私有属性precommit】,还有一个getprecommit()方法读取这个precommit信息。
从第二次commit开始,每次新建commit对象都会去调setprecommit方法来设置这个commit对象的precommit属性,然后再生成commitvalue时会调用这个getprecommit()方法把这个precommit信息写到commit的key-value文件里。
Comment thread 第二阶段任务解读.md Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里一定是根目录的tree key吧

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里一定是根目录的tree key吧

确实,谢谢学长指点!我突然想明白了。
我之前的想法是:commit时就提交一个blob上去,这种情况下就是一个blob key。
但我现在一想不对劲啊,虽然我现在第一次只提交了一个blob,但我后来要是又添加了别的新对象进去再commit,那到底是把新对象提交到哪去了呢?这就逻辑不通了。
所以肯定是存在一个根目录的,根目录存放所有这些增删改查的对象,所以提交内容一定是根目录的tree key。

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

假设说只提交了一个文本文件,blob里也只包含了这个文件的内容,文件名的信息还是需要tree来存的

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

确实确实,明白学长的意思!谢谢学长指点!
即便是后期不再加入新对象,只提交一个blob,那也必须得是tree来存,因为文件名字信息也是commit key的一部分!

经过学长指点,对commit提交内容的key作了修改:
提交内容的key一定是根目录的tree key
Comment thread 第二阶段任务解读.md Outdated
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@js00070
恳请学长看看我这种关于实现get和set一个precommitkey的想法是否符合要求。
首先提供私有属性precommitkey、公有方法setprecommitkey()、公有方法gettprecommitkey():
1.HEAD文件里只存放当前分支指向的commit,HEAD文件在第一次commit时产生。
2.commit类里有个私有成员域是precommitkey,有个setprecommitkey()方法【方法体就是读当前HEAD文件里那一条commitkey并附给私有属性precommitkey】,还有一个getprecommitkey()方法读取这个precommitkey信息。
3.从第二次commit开始,每次新建commit对象都会去调setprecommitkey方法来修改这个commit对象的precommitkey属性。在生成commit的value时会调用这个getprecommitkey()方法把修改后的precommitkey信息写到当前commit的key-value文件里。
ps:(如果HEAD文件里存放了多条分支的commitkey,那就需要先在HEAD文件中字符串匹配方法找到分支的名字,再去捕捉该分支对应的当前commitkey)。

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以写一个commit类,直接在这个类的构造函数里把commit的各种信息从key-value-store接口里得到的value中解析出来,这样就不用每次getXXX去读文件了

另外最好是单独再添加一个负责把commit id写到HEAD文件里的方法,和getprecommitkey分开,代码里只要是互相独立的逻辑,能拆开的就尽量拆开

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

明白学长的意思!这样做的确一目了然而且没有了重复冗余的操作!感谢您的宝贵建议!

Comment thread 第二阶段任务解读.md Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

branch是比commit更加上层的概念,最好也是和commit相关的逻辑分开

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

的确,branch里通过head指针能找到branch里的一系列commit。是更上层的概念!
框架逐渐清晰!感谢学长指点!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

第二阶段任务大纲和解读

2 participants