Skip to content

Conversation

@loach1528
Copy link
Collaborator

Basically completed the three-way merge of blob files, assuming there is a common ancestor node.


app = os.path.abspath(args.exe)

app = os.path.abspath('D:\learn\programming\s-git\s-git.exe')
Copy link
Owner

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){
Copy link
Owner

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){
Copy link
Owner

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) {
Copy link
Owner

Choose a reason for hiding this comment

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

readTree(ROOT_DIR.value(), ancestor.tree, ancestorEntries);
// 将 ancestorEntries 转换为set
std::unordered_set<object,object_hash, object_equal> ancestorSet;
for (auto &entry : ancestorEntries) {
Copy link
Owner

Choose a reason for hiding this comment

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

commit ancestor = LCA(currBranchCommit,mergeFromCommit);
std::cout << ancestor.message << std::endl;
// 三路归并文件树
// 1. 读取ancestor的文件树
Copy link
Owner

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") {
Copy link
Owner

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
Copy link
Owner

Choose a reason for hiding this comment

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

这个应该放到类似 checkout.h 的地方去声明。

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.

3 participants