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

Method OpenFile

src/TortoiseProc/RepositoryBrowser.cpp:1252–1316  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1250}
1251
1252void CRepositoryBrowser::OpenFile(const CString path, eOpenType mode, bool isSubmodule, const CGitHash& itemHash)
1253{
1254 CTGitPath gitPath(path);
1255
1256 CGitHash hash;
1257 if (g_Git.GetHash(hash, m_sRevision + L"^{}")) // add ^{} in order to dereference signed tags
1258 {
1259 MessageBox(g_Git.GetGitLastErr(L"Could not get hash of \"" + m_sRevision + L"^{}\"."), L"TortoiseGit", MB_ICONERROR);
1260 return;
1261 }
1262
1263 CString file = CTempFiles::Instance().GetTempFilePath(false, gitPath, hash).GetWinPathString();
1264 if (isSubmodule)
1265 {
1266 if (mode == OPEN && !GitAdminDir::IsBareRepo(g_Git.m_CurrentDir))
1267 {
1268 CTGitPath subPath = CTGitPath(g_Git.m_CurrentDir);
1269 subPath.AppendPathString(gitPath.GetWinPathString());
1270 CAutoRepository repo(subPath.GetGitPathString());
1271 CAutoCommit commit;
1272 if (!repo || git_commit_lookup(commit.GetPointer(), repo, itemHash))
1273 {
1274 CString out;
1275 out.FormatMessage(IDS_REPOBROWSEASKSUBMODULEUPDATE, static_cast<LPCWSTR>(itemHash.ToString()), static_cast<LPCWSTR>(gitPath.GetGitPathString()));
1276 if (MessageBox(out, L"TortoiseGit", MB_YESNO | MB_ICONQUESTION) != IDYES)
1277 return;
1278
1279 CString sCmd;
1280 sCmd.Format(L"/command:subupdate /bkpath:\"%s\" /selectedpath:%s", static_cast<LPCWSTR>(g_Git.m_CurrentDir), static_cast<LPCWSTR>(CCmdLineParser::EscapeValue(gitPath.GetGitPathString())));
1281 CAppUtils::RunTortoiseGitProc(sCmd);
1282 return;
1283 }
1284
1285 CString cmd;
1286 cmd.Format(L"/command:repobrowser /path:%s /rev:%s", static_cast<LPCWSTR>(CCmdLineParser::EscapeValue(g_Git.CombinePath(path))), static_cast<LPCWSTR>(itemHash.ToString()));
1287 CAppUtils::RunTortoiseGitProc(cmd);
1288 return;
1289 }
1290
1291 file += L".txt";
1292 CFile submoduleCommit(file, CFile::modeCreate | CFile::modeWrite);
1293 CStringA commitInfo = "Subproject commit " + CStringA(itemHash.ToString());
1294 submoduleCommit.Write(commitInfo, commitInfo.GetLength());
1295 }
1296 else if (g_Git.GetOneFile(m_sRevision, gitPath, file))
1297 {
1298 CString out;
1299 out.FormatMessage(IDS_STATUSLIST_CHECKOUTFILEFAILED, static_cast<LPCWSTR>(gitPath.GetGitPathString()), static_cast<LPCWSTR>(m_sRevision), static_cast<LPCWSTR>(file));
1300 MessageBox(g_Git.GetGitLastErr(out, CGit::GIT_CMD_GETONEFILE), L"TortoiseGit", MB_ICONERROR);
1301 return;
1302 }
1303
1304 if (mode == ALTERNATIVEEDITOR)
1305 {
1306 CAppUtils::LaunchAlternativeEditor(file);
1307 return;
1308 }
1309 else if (mode == OPEN)

Callers

nothing calls this directly

Calls 11

GetHashMethod · 0.80
GetGitLastErrMethod · 0.80
AppendPathStringMethod · 0.80
CombinePathMethod · 0.80
GetOneFileMethod · 0.80
CTGitPathClass · 0.70
GetTempFilePathMethod · 0.45
GetPointerMethod · 0.45
ToStringMethod · 0.45
WriteMethod · 0.45
GetLengthMethod · 0.45

Tested by

no test coverage detected