diff --git a/plugins/vcs/Repository.cpp b/plugins/vcs/Repository.cpp index afd8d0c5c6..7f928365ee 100644 --- a/plugins/vcs/Repository.cpp +++ b/plugins/vcs/Repository.cpp @@ -301,11 +301,8 @@ std::shared_ptr 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); + auto commit = Commit::LookupFromOid(_repository, &revisionOid); + return commit->getTree(); } bool Repository::isReadyForMerge() diff --git a/plugins/vcs/Tree.h b/plugins/vcs/Tree.h index 18ff5370ba..f48f9a65b0 100644 --- a/plugins/vcs/Tree.h +++ b/plugins/vcs/Tree.h @@ -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(blob, filePath);