| 2779 | } |
| 2780 | |
| 2781 | int CGit::GetOneFile(const CString &Refname, const CTGitPath &path, const CString &outputfile) |
| 2782 | { |
| 2783 | if (UsingLibGit2(GIT_CMD_GETONEFILE)) |
| 2784 | { |
| 2785 | CAutoRepository repo(GetGitRepository()); |
| 2786 | if (!repo) |
| 2787 | return -1; |
| 2788 | |
| 2789 | CGitHash hash; |
| 2790 | if (GetHash(repo, hash, Refname + L"^{}")) // add ^{} in order to dereference signed tags |
| 2791 | return -1; |
| 2792 | |
| 2793 | CAutoCommit commit; |
| 2794 | if (git_commit_lookup(commit.GetPointer(), repo, hash)) |
| 2795 | return -1; |
| 2796 | |
| 2797 | CAutoTree tree; |
| 2798 | if (git_commit_tree(tree.GetPointer(), commit)) |
| 2799 | return -1; |
| 2800 | |
| 2801 | CAutoTreeEntry entry; |
| 2802 | if (auto ret = git_tree_entry_bypath(entry.GetPointer(), tree, CUnicodeUtils::GetUTF8(path.GetGitPathString())); ret) |
| 2803 | return ret; |
| 2804 | |
| 2805 | if (git_tree_entry_filemode(entry) == GIT_FILEMODE_COMMIT) |
| 2806 | { |
| 2807 | git_error_set_str(GIT_ERROR_NONE, "The requested object is a submodule and not a file."); |
| 2808 | return -1; |
| 2809 | } |
| 2810 | |
| 2811 | CAutoBlob blob; |
| 2812 | if (git_tree_entry_to_object(reinterpret_cast<git_object**>(blob.GetPointer()), repo, entry)) |
| 2813 | return -1; |
| 2814 | |
| 2815 | CAutoFILE file = _wfsopen(outputfile, L"wb", SH_DENYWR); |
| 2816 | if (file == nullptr) |
| 2817 | { |
| 2818 | git_error_set_str(GIT_ERROR_NONE, "Could not create file."); |
| 2819 | return -1; |
| 2820 | } |
| 2821 | CAutoBuf buf; |
| 2822 | git_blob_filter_options opts = GIT_BLOB_FILTER_OPTIONS_INIT; |
| 2823 | opts.flags &= ~static_cast<uint32_t>(GIT_BLOB_FILTER_CHECK_FOR_BINARY); |
| 2824 | if (git_blob_filter(buf, blob, CUnicodeUtils::GetUTF8(path.GetGitPathString()), &opts)) |
| 2825 | return -1; |
| 2826 | if (fwrite(buf->ptr, sizeof(char), buf->size, file) != buf->size) |
| 2827 | { |
| 2828 | git_error_set_str(GIT_ERROR_OS, "Could not write to file."); |
| 2829 | return -1; |
| 2830 | } |
| 2831 | |
| 2832 | return 0; |
| 2833 | } |
| 2834 | else if (g_Git.m_IsUseGitDLL) |
| 2835 | { |
| 2836 | CAutoLocker lock(g_Git.m_critGitDllSec); |
| 2837 | try |
| 2838 | { |