-
Notifications
You must be signed in to change notification settings - Fork 0
Merge #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
|
||
| app = os.path.abspath(args.exe) | ||
|
|
||
| app = os.path.abspath('D:\learn\programming\s-git\s-git.exe') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这种不要commit进来,要是懒得传arg,可以改成optional的,然后用relative path。
| return 0; | ||
| } | ||
|
|
||
| int checkout(std::string branch){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reuse this function in line 187-214.
| return commitSha1; | ||
| } | ||
|
|
||
| struct commit Parent(struct commit child){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can child be const?
| if (buffer.has_value()) write_file(path, buffer.value()); | ||
| } | ||
|
|
||
| std::optional<std::string> resolveBranch(std::string &branch) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This duplicate with https://github.com/MMaxwell66/s-git/blob/b6c24c5beaa32a5d6baf5747e6afe2b4848aca73/checkout/checkout.cpp#L119 Can we move into a common location?
| readTree(ROOT_DIR.value(), ancestor.tree, ancestorEntries); | ||
| // 将 ancestorEntries 转换为set | ||
| std::unordered_set<object,object_hash, object_equal> ancestorSet; | ||
| for (auto &entry : ancestorEntries) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://en.cppreference.com/w/cpp/container/unordered_set/unordered_set 能用6/7这种Iterator的构造函数吗?
| commit ancestor = LCA(currBranchCommit,mergeFromCommit); | ||
| std::cout << ancestor.message << std::endl; | ||
| // 三路归并文件树 | ||
| // 1. 读取ancestor的文件树 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
重复了三次,可以抽一个function出来。
| } | ||
|
|
||
| object mergeFile(object based,object source,object curr){ | ||
| if (based.object_type == "blob") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, 有一种写法的目的是为了减少代码的缩进,我比较推荐一点。
if (base.object_type != "blob") return /**/;
// following code has one less indentation.| } | ||
|
|
||
| //直接将当前分支指向mergeFromCommit | ||
| extern |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个应该放到类似 checkout.h 的地方去声明。
Basically completed the three-way merge of blob files, assuming there is a common ancestor node.