MCPcopy Create free account
hub / github.com/TortoiseGit/TortoiseGit / GetOneFile

Method GetOneFile

src/Git/Git.cpp:2781–2873  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2779}
2780
2781int 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 {

Callers 15

GetOneFileFunction · 0.80
GetOneFile_utf8Function · 0.80
TEST_PFunction · 0.80
StartDiffMethod · 0.80
FilesExportMethod · 0.80
FileSaveAsMethod · 0.80
OpenFileMethod · 0.80
GetDataMethod · 0.80
ReadPropsMethod · 0.80
OnContextMenuMethod · 0.80
DiffNullMethod · 0.80
DiffMethod · 0.80

Calls 6

GetHashFunction · 0.85
git_checkout_fileFunction · 0.85
CheckAndInitDllMethod · 0.80
causeMethod · 0.80
GetPointerMethod · 0.45
EmptyMethod · 0.45

Tested by 3

GetOneFileFunction · 0.64
GetOneFile_utf8Function · 0.64
TEST_PFunction · 0.64