Skip to content

Commit

Permalink
#5662: Implementation fixup, VCS loading now working
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jul 17, 2021
1 parent f7b9da1 commit a00a347
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
7 changes: 2 additions & 5 deletions plugins/vcs/Repository.cpp
Expand Up @@ -301,11 +301,8 @@ std::shared_ptr<Tree> Repository::getTreeByRevision(const std::string& revision)
auto error = git_oid_fromstr(&revisionOid, revision.c_str());
GitException::ThrowOnError(error);

git_tree* tree;
error = git_tree_lookup(&tree, _repository, &revisionOid);
GitException::ThrowOnError(error);

return std::make_shared<Tree>(tree);
auto commit = Commit::LookupFromOid(_repository, &revisionOid);
return commit->getTree();
}

bool Repository::isReadyForMerge()
Expand Down
16 changes: 12 additions & 4 deletions plugins/vcs/Tree.h
Expand Up @@ -28,12 +28,20 @@ class Tree final
GitArchiveTextFile::Ptr openTextFile(const std::string& filePath, Repository& repository)
{
// Tree entry is owned by the tree, it's not allowed to free it
auto entry = git_tree_entry_byname(_tree, filePath.c_str());

if (!entry) throw GitException("File not found: " + filePath);
git_tree_entry* entry = nullptr;
auto error = git_tree_entry_bypath(&entry, _tree, filePath.c_str());
GitException::ThrowOnError(error);

git_blob* blob;
git_blob_lookup(&blob, repository._get(), git_tree_entry_id(entry));
error = git_blob_lookup(&blob, repository._get(), git_tree_entry_id(entry));

// Free the entry before checking for errors
git_tree_entry_free(entry);

if (error < 0)
{
GitException::ThrowOnError(error);
}

// GitArchiveTextFile assumes ownership of the blob
return std::make_shared<GitArchiveTextFile>(blob, filePath);
Expand Down

0 comments on commit a00a347

Please sign in to comment.