bool SVNDiff::ShowUnifiedDiff(const CTSVNPath& url1, const SVNRev& rev1, const CTSVNPath& url2, const SVNRev& rev2, SVNRev peg, const CString& options, bool bIgnoreAncestry /* = false */, bool /*blame*/, bool bIgnoreProperties /* = true */) { CTSVNPath tempfile; if (UnifiedDiff(tempfile, url1, rev1, url2, rev2, peg, options, bIgnoreAncestry, bIgnoreProperties)) { CString title; CTSVNPathList list; list.AddPath(url1); list.AddPath(url2); if (url1.IsEquivalentTo(url2)) title.FormatMessage(IDS_SVNDIFF_ONEURL, (LPCTSTR)rev1.ToString(), (LPCTSTR)rev2.ToString(), (LPCTSTR)url1.GetUIFileOrDirectoryName()); else { CTSVNPath root = list.GetCommonRoot(); CString u1 = url1.GetUIPathString().Mid(root.GetUIPathString().GetLength()); CString u2 = url2.GetUIPathString().Mid(root.GetUIPathString().GetLength()); title.FormatMessage(IDS_SVNDIFF_TWOURLS, (LPCTSTR)rev1.ToString(), (LPCTSTR)u1, (LPCTSTR)rev2.ToString(), (LPCTSTR)u2); } return !!CAppUtils::StartUnifiedDiffViewer(tempfile.GetWinPathString(), title); } return false; }
void CUpdateDlg::OnBnClickedSparse() { UpdateData(); CString strURLs; CTSVNPathList paths; paths.LoadFromAsteriskSeparatedString (strURLs); SVN svn; CString strUrl = svn.GetURLFromPath(m_wcPath); CRepositoryBrowser browser(strUrl, SVNRev::REV_HEAD, this); browser.SetSparseCheckoutMode(m_wcPath); if (browser.DoModal() == IDOK) { m_checkoutDepths = browser.GetUpdateDepths(); CString sCustomDepth = CString(MAKEINTRESOURCE(IDS_SVN_DEPTH_CUSTOM)); int customIndex = m_depthCombo.FindStringExact(-1, sCustomDepth); if (customIndex == CB_ERR) { customIndex = m_depthCombo.AddString(sCustomDepth); } m_depthCombo.SetCurSel(customIndex); } }
bool CTSVNPathList::IsEqual(const CTSVNPathList& list) { if (list.GetCount() != GetCount()) return false; for (int i=0; i<list.GetCount(); ++i) { if (!list[i].IsEquivalentTo(m_paths[i])) return false; } return true; }
CTSVNPathList CRepositoryBrowserSelection::GetURLsEscaped (size_t repositoryIndex) const { CTSVNPathList result; const SPathsPerRepository& info = repositories[repositoryIndex]; for (size_t i = 0, count = info.paths.size(); i < count; ++i) result.AddPath (info.paths[i].urlEscaped); return result; }
/** * Add a list of paths for updating. * The update will happen when the list is destroyed, at the end of execution */ void CShellUpdater::AddPathsForUpdate(const CTSVNPathList& pathList) { for(int nPath=0; nPath < pathList.GetCount(); nPath++) { AddPathForUpdate(pathList[nPath]); } }
void CHooks::AddCWDParam(CString& sCmd, const CTSVNPathList& pathList) { CTSVNPath curDir = pathList.GetCommonRoot().GetDirectory(); while (!curDir.IsEmpty() && !curDir.Exists()) curDir = curDir.GetContainingDirectory(); AddParam(sCmd, curDir.GetWinPathString()); }
bool RenameCommand::RenameWithReplace(HWND hWnd, const CTSVNPathList &srcPathList, const CTSVNPath &destPath, const CString &message /* = L"" */, bool move_as_child /* = false */, bool make_parents /* = false */) const { SVN svn; UINT idret = IDYES; bool bRet = true; if (destPath.Exists() && !destPath.IsDirectory() && !destPath.IsEquivalentToWithoutCase(srcPathList[0])) { CString sReplace; sReplace.Format(IDS_PROC_REPLACEEXISTING, destPath.GetWinPath()); CTaskDialog taskdlg(sReplace, CString(MAKEINTRESOURCE(IDS_PROC_REPLACEEXISTING_TASK2)), L"TortoiseSVN", 0, TDF_USE_COMMAND_LINKS | TDF_ALLOW_DIALOG_CANCELLATION | TDF_POSITION_RELATIVE_TO_WINDOW); taskdlg.AddCommandControl(1, CString(MAKEINTRESOURCE(IDS_PROC_REPLACEEXISTING_TASK3))); taskdlg.AddCommandControl(2, CString(MAKEINTRESOURCE(IDS_PROC_REPLACEEXISTING_TASK4))); taskdlg.SetCommonButtons(TDCBF_CANCEL_BUTTON); taskdlg.SetDefaultCommandControl(2); taskdlg.SetMainIcon(TD_WARNING_ICON); INT_PTR ret = taskdlg.DoModal(hWnd); if (ret == 1) // replace idret = IDYES; else idret = IDNO; if (idret == IDYES) { if (!svn.Remove(CTSVNPathList(destPath), true, false)) { destPath.Delete(true); } } } if ((idret != IDNO)&&(!svn.Move(srcPathList, destPath, message, move_as_child, make_parents))) { auto apr_err = svn.GetSVNError()->apr_err; if ((apr_err == SVN_ERR_ENTRY_NOT_FOUND) || (apr_err == SVN_ERR_WC_PATH_NOT_FOUND)) { bRet = !!MoveFile(srcPathList[0].GetWinPath(), destPath.GetWinPath()); } else { svn.ShowErrorDialog(hWnd, srcPathList.GetCommonDirectory()); bRet = false; } } if (idret == IDNO) bRet = false; return bRet; }
bool ShelveCommand::Shelve(const CString& shelveName, const CTSVNPathList& paths) { CProgressDlg progDlg; progDlg.SetTitle(IDS_PROC_PATCHTITLE); progDlg.SetShowProgressBar(false); progDlg.ShowModeless(CWnd::FromHandle(GetExplorerHWND())); CTSVNPath sDir = paths.GetCommonRoot(); SVN svn; if (!svn.Shelve(shelveName, paths, svn_depth_infinity /*, changelists*/)) { progDlg.Stop(); svn.ShowErrorDialog(GetExplorerHWND(), sDir); return FALSE; } progDlg.Stop(); return TRUE; }
hookiterator CHooks::FindItem(hooktype t, const CTSVNPathList& pathList) { hookkey key; for (int i=0; i<pathList.GetCount(); ++i) { CTSVNPath path = pathList[i]; do { key.htype = t; key.path = path; hookiterator it = find(key); if (it != end()) { return it; } path = path.GetContainingDirectory(); } while(!path.IsEmpty()); } // try the wc root path key.htype = t; key.path = m_wcRootPath; hookiterator it = find(key); if (it != end()) { return it; } // look for a script with a path as '*' key.htype = t; key.path = CTSVNPath(L"*"); it = find(key); if (it != end()) { return it; } return end(); }
bool CHooks::PreConnect(const CTSVNPathList& pathList) { if ((m_lastPreConnectTicks == 0) || ((GetTickCount64() - m_lastPreConnectTicks) > 5*60*1000)) { hookiterator it = FindItem(pre_connect_hook, pathList); if (it == end()) { if (!m_PathsConvertedToUrls && pathList.GetCount() && pathList[0].IsUrl()) { SVN svn; for (hookiterator ith = begin(); ith != end(); ++ith) { if (ith->first.htype == pre_connect_hook) { CString sUrl = svn.GetURLFromPath(ith->first.path); hookkey hk; hk.htype = pre_connect_hook; hk.path = CTSVNPath(sUrl); insert(std::pair<hookkey, hookcmd>(hk, ith->second)); } } m_PathsConvertedToUrls = true; it = FindItem(pre_connect_hook, pathList); if (it == end()) return false; } else return false; } CString sCmd = it->second.commandline; CString error; RunScript(sCmd, pathList, error, it->second.bWait, it->second.bShow); m_lastPreConnectTicks = GetTickCount64(); return true; } return false; }
void ListLoadingTest() { TCHAR buf[MAX_PATH] = { 0 }; GetCurrentDirectory(_countof(buf), buf); CString sPathList(L"Path1*c:\\path2 with spaces and stuff*\\funnypath\\*"); CTSVNPathList testList; testList.LoadFromAsteriskSeparatedString(sPathList); ATLASSERT(testList.GetCount() == 3); ATLASSERT(testList[0].GetWinPathString() == CString(buf) + L"\\Path1"); ATLASSERT(testList[1].GetWinPathString() == L"c:\\path2 with spaces and stuff"); ATLASSERT(testList[2].GetWinPathString() == L"\\funnypath"); ATLASSERT(testList.GetCommonRoot().GetWinPathString().IsEmpty()); sPathList = L"c:\\path2 with spaces and stuff*c:\\funnypath\\*"; testList.LoadFromAsteriskSeparatedString(sPathList); ATLASSERT(testList.GetCommonRoot().GetWinPathString() == L"c:\\"); }
void SortTest() { CTSVNPathList testList; CTSVNPath testPath; testPath.SetFromUnknown(L"c:/Z"); testList.AddPath(testPath); testPath.SetFromUnknown(L"c:/B"); testList.AddPath(testPath); testPath.SetFromUnknown(L"c:\\a"); testList.AddPath(testPath); testPath.SetFromUnknown(L"c:/Test"); testList.AddPath(testPath); testList.SortByPathname(); ATLASSERT(testList[0].GetWinPathString() == L"c:\\a"); ATLASSERT(testList[1].GetWinPathString() == L"c:\\B"); ATLASSERT(testList[2].GetWinPathString() == L"c:\\Test"); ATLASSERT(testList[3].GetWinPathString() == L"c:\\Z"); }
void RemoveDuplicatesTest() { CTSVNPathList list; list.AddPath(CTSVNPath(L"Z")); list.AddPath(CTSVNPath(L"A")); list.AddPath(CTSVNPath(L"E")); list.AddPath(CTSVNPath(L"E")); ATLASSERT(list[2].IsEquivalentTo(list[3])); ATLASSERT(list[2]==list[3]); ATLASSERT(list.GetCount() == 4); list.RemoveDuplicates(); ATLASSERT(list.GetCount() == 3); ATLASSERT(list[0].GetWinPathString() == L"A"); ATLASSERT(list[1].GetWinPathString().Compare(L"E") == 0); ATLASSERT(list[2].GetWinPathString() == L"Z"); }
void AdminDirTest() { CTSVNPath testPath; testPath.SetFromUnknown(L"c:\\.svndir"); ATLASSERT(!testPath.IsAdminDir()); testPath.SetFromUnknown(L"c:\\test.svn"); ATLASSERT(!testPath.IsAdminDir()); testPath.SetFromUnknown(L"c:\\.svn"); ATLASSERT(testPath.IsAdminDir()); testPath.SetFromUnknown(L"c:\\.svndir\\test"); ATLASSERT(!testPath.IsAdminDir()); testPath.SetFromUnknown(L"c:\\.svn\\test"); ATLASSERT(testPath.IsAdminDir()); CTSVNPathList pathList; pathList.AddPath(CTSVNPath(L"c:\\.svndir")); pathList.AddPath(CTSVNPath(L"c:\\.svn")); pathList.AddPath(CTSVNPath(L"c:\\.svn\\test")); pathList.AddPath(CTSVNPath(L"c:\\test")); pathList.RemoveAdminPaths(); ATLASSERT(pathList.GetCount()==2); pathList.Clear(); pathList.AddPath(CTSVNPath(L"c:\\test")); pathList.RemoveAdminPaths(); ATLASSERT(pathList.GetCount()==1); }
bool CleanupCommand::Execute() { bool bRet = false; CCleanTypeDlg dlg; if( dlg.DoModal() == IDOK) { bool quotepath = g_Git.GetConfigValueBool(_T("core.quotepath")); CString cmd; cmd.Format(_T("git.exe clean")); if (dlg.m_bDryRun || !dlg.m_bNoRecycleBin) cmd += _T(" -n "); if(dlg.m_bDir) cmd += _T(" -d "); switch(dlg.m_CleanType) { case 0: cmd += _T(" -fx"); break; case 1: cmd += _T(" -f"); break; case 2: cmd += _T(" -fX"); break; } STRING_VECTOR submoduleList; SubmodulePayload payload(submoduleList); if (dlg.m_bSubmodules) { payload.basePath = CTGitPath(g_Git.m_CurrentDir).GetGitPathString(); if (pathList.GetCount() != 1 || pathList.GetCount() == 1 && !pathList[0].IsEmpty()) { for (int i = 0; i < pathList.GetCount(); ++i) { CString path; if (pathList[i].IsDirectory()) payload.prefixList.push_back(pathList[i].GetGitPathString()); else payload.prefixList.push_back(pathList[i].GetContainingDirectory().GetGitPathString()); } } if (!GetSubmodulePathList(payload)) return FALSE; std::sort(submoduleList.begin(), submoduleList.end()); } if (dlg.m_bDryRun || dlg.m_bNoRecycleBin) { while (true) { CProgressDlg progress; for (int i = 0; i < this->pathList.GetCount(); ++i) { CString path; if (this->pathList[i].IsDirectory()) path = pathList[i].GetGitPathString(); else path = pathList[i].GetContainingDirectory().GetGitPathString(); progress.m_GitDirList.push_back(g_Git.m_CurrentDir); progress.m_GitCmdList.push_back(cmd + _T(" \"") + path + _T("\"")); } if (dlg.m_bSubmodules) { for (CString dir : submoduleList) { progress.m_GitDirList.push_back(CTGitPath(dir).GetWinPathString()); progress.m_GitCmdList.push_back(cmd); } } INT_PTR idRetry = -1; if (!dlg.m_bDryRun) idRetry = progress.m_PostFailCmdList.Add(CString(MAKEINTRESOURCE(IDS_MSGBOX_RETRY))); INT_PTR result = progress.DoModal(); if (result == IDOK) return TRUE; if (progress.m_GitStatus && result == IDC_PROGRESS_BUTTON1 + idRetry) continue; break; } } else { CSysProgressDlg sysProgressDlg; sysProgressDlg.SetAnimation(IDR_CLEANUPANI); sysProgressDlg.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME))); sysProgressDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_CLEANUP_INFO1))); sysProgressDlg.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT))); sysProgressDlg.SetShowProgressBar(false); sysProgressDlg.ShowModeless((HWND)NULL, true); CTGitPathList delList; for (size_t i = 0; i <= submoduleList.size(); ++i) { CGit git; CGit *pGit; if (i == 0) pGit = &g_Git; else { git.m_CurrentDir = submoduleList[i - 1]; pGit = &git; } CString cmdout, cmdouterr; if (pGit->Run(cmd, &cmdout, &cmdouterr, CP_UTF8)) { MessageBox(nullptr, cmdouterr, _T("TortoiseGit"), MB_ICONERROR); return FALSE; } if (sysProgressDlg.HasUserCancelled()) { CMessageBox::Show(nullptr, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_OK); return FALSE; } int pos = 0; CString token = cmdout.Tokenize(_T("\n"), pos); while (!token.IsEmpty()) { if (token.Mid(0, 13) == _T("Would remove ")) { CString tempPath = token.Mid(13).TrimRight(); if (quotepath) { tempPath = UnescapeQuotePath(tempPath.Trim(_T('"'))); } if (i == 0) delList.AddPath(CTGitPath(tempPath)); else delList.AddPath(CTGitPath(submoduleList[i - 1] + "/" + tempPath)); } token = cmdout.Tokenize(_T("\n"), pos); } if (sysProgressDlg.HasUserCancelled()) { CMessageBox::Show(nullptr, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_OK); return FALSE; } } delList.DeleteAllFiles(true, false); sysProgressDlg.Stop(); } } #if 0 CProgressDlg progress; progress.SetTitle(IDS_PROC_CLEANUP); progress.SetAnimation(IDR_CLEANUPANI); progress.SetShowProgressBar(false); progress.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_CLEANUP_INFO1))); progress.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROC_CLEANUP_INFO2))); progress.ShowModeless(hwndExplorer); CString strSuccessfullPaths, strFailedPaths; for (int i=0; i<pathList.GetCount(); ++i) { SVN svn; if (!svn.CleanUp(pathList[i])) { strFailedPaths += _T("- ") + pathList[i].GetWinPathString() + _T("\n"); strFailedPaths += svn.GetLastErrorMessage() + _T("\n\n"); } else { strSuccessfullPaths += _T("- ") + pathList[i].GetWinPathString() + _T("\n"); // after the cleanup has finished, crawl the path downwards and send a change // notification for every directory to the shell. This will update the // overlays in the left tree view of the explorer. CDirFileEnum crawler(pathList[i].GetWinPathString()); CString sPath; bool bDir = false; CTSVNPathList updateList; while (crawler.NextFile(sPath, &bDir)) { if ((bDir) && (!g_SVNAdminDir.IsAdminDirPath(sPath))) { updateList.AddPath(CTSVNPath(sPath)); } } updateList.AddPath(pathList[i]); CShellUpdater::Instance().AddPathsForUpdate(updateList); CShellUpdater::Instance().Flush(); updateList.SortByPathname(true); for (INT_PTR i=0; i<updateList.GetCount(); ++i) { SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, updateList[i].GetWinPath(), NULL); CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) _T(": notify change for path %s\n"), updateList[i].GetWinPath()); } } } progress.Stop(); CString strMessage; if ( !strSuccessfullPaths.IsEmpty() ) { CString tmp; tmp.Format(IDS_PROC_CLEANUPFINISHED, (LPCTSTR)strSuccessfullPaths); strMessage += tmp; bRet = true; } if ( !strFailedPaths.IsEmpty() ) { if (!strMessage.IsEmpty()) strMessage += _T("\n"); CString tmp; tmp.Format(IDS_PROC_CLEANUPFINISHED_FAILED, (LPCTSTR)strFailedPaths); strMessage += tmp; bRet = false; } CMessageBox::Show(hwndExplorer, strMessage, _T("TortoiseGit"), MB_OK | (strFailedPaths.IsEmpty()?MB_ICONINFORMATION:MB_ICONERROR)); #endif CShellUpdater::Instance().Flush(); return bRet; }
void CCachedDirectory::RefreshStatus(bool bRecursive) { // Make sure that our own status is up-to-date GetStatusForMember(m_directoryPath,bRecursive); CTSVNPathList updatePathList; CTSVNPathList crawlPathList; CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) _T(": RefreshStatus for %s\n"), m_directoryPath.GetWinPath()); DWORD now = GetTickCount(); { // get the file write times with FindFirstFile/FindNextFile since those // APIs only access the folder, not each file individually. // This reduces the disk access a *lot*. std::map<CStringA, ULONGLONG> filetimes; WIN32_FIND_DATA FindFileData; CAutoFindFile hFind = FindFirstFile(m_directoryPath.GetWinPathString() + L"\\*.*", &FindFileData); if (hFind) { while (FindNextFile(hFind, &FindFileData)) { if ( (wcscmp(FindFileData.cFileName, L"..")==0) || (wcscmp(FindFileData.cFileName, L".")==0) ) continue; ULARGE_INTEGER ft; ft.LowPart = FindFileData.ftLastWriteTime.dwLowDateTime; ft.HighPart = FindFileData.ftLastWriteTime.dwHighDateTime; CStringA nameUTF8 = CUnicodeUtils::GetUTF8(FindFileData.cFileName); filetimes[nameUTF8] = ft.QuadPart; } hFind.CloseHandle(); // explicit close handle to shorten its life time } AutoLocker lock(m_critSec); // We also need to check if all our file members have the right date on them for (CacheEntryMap::iterator itMembers = m_entryCache.begin(); itMembers != m_entryCache.end(); ++itMembers) { if ((itMembers->first)&&(!itMembers->first.IsEmpty())) { CTSVNPath filePath (GetFullPathString (itMembers->first)); if (!filePath.IsEquivalentToWithoutCase(m_directoryPath)) { // we only have file members in our entry cache ATLASSERT(!itMembers->second.IsDirectory()); auto ftIt = filetimes.find(itMembers->first.Mid(1)); if (ftIt != filetimes.end()) { ULONGLONG ft = ftIt->second; if ((itMembers->second.HasExpired(now))||(!itMembers->second.DoesFileTimeMatch(ft))) { // We need to request this item as well updatePathList.AddPath(filePath); } } } } } if (bRecursive) { // crawl all sub folders too! Otherwise a change deep inside the // tree which has changed won't get propagated up the tree. for(ChildDirStatus::const_iterator it = m_childDirectories.begin(); it != m_childDirectories.end(); ++it) { CTSVNPath path; CString winPath = CUnicodeUtils::GetUnicode (it->first); path.SetFromWin (winPath, true); crawlPathList.AddPath(path); } } } for (int i = 0; i < updatePathList.GetCount(); ++i) GetStatusForMember(updatePathList[i], bRecursive); for (int i = 0; i < crawlPathList.GetCount(); ++i) CSVNStatusCache::Instance().AddFolderForCrawling(crawlPathList[i]); }
bool CleanupCommand::Execute() { bool bRet = false; CCleanTypeDlg dlg; if( dlg.DoModal() == IDOK) { bool quotepath = g_Git.GetConfigValueBool(_T("core.quotepath")); CString cmd; cmd.Format(_T("git clean")); if (dlg.m_bDryRun || !dlg.m_bNoRecycleBin) cmd += _T(" -n "); if(dlg.m_bDir) cmd += _T(" -d "); switch(dlg.m_CleanType) { case 0: cmd += _T(" -fx"); break; case 1: cmd += _T(" -f"); break; case 2: cmd += _T(" -fX"); break; } if (dlg.m_bDryRun || dlg.m_bNoRecycleBin) { CProgressDlg progress; for (int i = 0; i < this->pathList.GetCount(); ++i) { CString path; if (this->pathList[i].IsDirectory()) path = pathList[i].GetGitPathString(); else path = pathList[i].GetContainingDirectory().GetGitPathString(); progress.m_GitCmdList.push_back(cmd + _T(" \"") + path + _T("\"")); } if (progress.DoModal()==IDOK) return TRUE; } else { CSysProgressDlg sysProgressDlg; sysProgressDlg.SetAnimation(IDR_CLEANUPANI); sysProgressDlg.SetTitle(CString(MAKEINTRESOURCE(IDS_APPNAME))); sysProgressDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_CLEANUP_INFO1))); sysProgressDlg.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROGRESSWAIT))); sysProgressDlg.SetShowProgressBar(false); sysProgressDlg.ShowModeless((HWND)NULL, true); CString cmdout, cmdouterr; if (g_Git.Run(cmd, &cmdout, &cmdouterr, CP_UTF8)) { MessageBox(NULL, cmdouterr, _T("TortoiseGit"), MB_ICONERROR); return FALSE; } if (sysProgressDlg.HasUserCancelled()) { CMessageBox::Show(NULL, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_OK); return FALSE; } int pos = 0; CString token = cmdout.Tokenize(_T("\n"), pos); CTGitPathList delList; while (!token.IsEmpty()) { if (token.Mid(0, 13) == _T("Would remove ")) { CString tempPath = token.Mid(13).TrimRight(); if (quotepath) { tempPath = UnescapeQuotePath(tempPath.Trim(_T('"'))); } delList.AddPath(CTGitPath(tempPath)); } token = cmdout.Tokenize(_T("\n"), pos); } if (sysProgressDlg.HasUserCancelled()) { CMessageBox::Show(NULL, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_OK); return FALSE; } delList.DeleteAllFiles(true, false); sysProgressDlg.Stop(); } } #if 0 CProgressDlg progress; progress.SetTitle(IDS_PROC_CLEANUP); progress.SetAnimation(IDR_CLEANUPANI); progress.SetShowProgressBar(false); progress.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_CLEANUP_INFO1))); progress.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROC_CLEANUP_INFO2))); progress.ShowModeless(hwndExplorer); CString strSuccessfullPaths, strFailedPaths; for (int i=0; i<pathList.GetCount(); ++i) { SVN svn; if (!svn.CleanUp(pathList[i])) { strFailedPaths += _T("- ") + pathList[i].GetWinPathString() + _T("\n"); strFailedPaths += svn.GetLastErrorMessage() + _T("\n\n"); } else { strSuccessfullPaths += _T("- ") + pathList[i].GetWinPathString() + _T("\n"); // after the cleanup has finished, crawl the path downwards and send a change // notification for every directory to the shell. This will update the // overlays in the left tree view of the explorer. CDirFileEnum crawler(pathList[i].GetWinPathString()); CString sPath; bool bDir = false; CTSVNPathList updateList; while (crawler.NextFile(sPath, &bDir)) { if ((bDir) && (!g_SVNAdminDir.IsAdminDirPath(sPath))) { updateList.AddPath(CTSVNPath(sPath)); } } updateList.AddPath(pathList[i]); CShellUpdater::Instance().AddPathsForUpdate(updateList); CShellUpdater::Instance().Flush(); updateList.SortByPathname(true); for (INT_PTR i=0; i<updateList.GetCount(); ++i) { SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, updateList[i].GetWinPath(), NULL); ATLTRACE(_T("notify change for path %s\n"), updateList[i].GetWinPath()); } } } progress.Stop(); CString strMessage; if ( !strSuccessfullPaths.IsEmpty() ) { CString tmp; tmp.Format(IDS_PROC_CLEANUPFINISHED, (LPCTSTR)strSuccessfullPaths); strMessage += tmp; bRet = true; } if ( !strFailedPaths.IsEmpty() ) { if (!strMessage.IsEmpty()) strMessage += _T("\n"); CString tmp; tmp.Format(IDS_PROC_CLEANUPFINISHED_FAILED, (LPCTSTR)strFailedPaths); strMessage += tmp; bRet = false; } CMessageBox::Show(hwndExplorer, strMessage, _T("TortoiseGit"), MB_OK | (strFailedPaths.IsEmpty()?MB_ICONINFORMATION:MB_ICONERROR)); #endif CShellUpdater::Instance().Flush(); return bRet; }
DWORD CHooks::RunScript(CString cmd, const CTSVNPathList& paths, CString& error, bool bWait, bool bShow) { DWORD exitcode = 0; SECURITY_ATTRIBUTES sa; SecureZeroMemory(&sa, sizeof(sa)); sa.nLength = sizeof(sa); sa.bInheritHandle = TRUE; CTSVNPath curDir = paths.GetCommonRoot().GetDirectory(); while (!curDir.IsEmpty() && !curDir.Exists()) curDir = curDir.GetContainingDirectory(); if (curDir.IsEmpty()) { WCHAR buf[MAX_PATH] = {0}; GetTempPath(MAX_PATH, buf); curDir.SetFromWin(buf, true); } CAutoFile hOut ; CAutoFile hRedir; CAutoFile hErr; // clear the error string error.Empty(); // Create Temp File for redirection TCHAR szTempPath[MAX_PATH] = { 0 }; TCHAR szOutput[MAX_PATH] = { 0 }; TCHAR szErr[MAX_PATH] = { 0 }; GetTempPath(_countof(szTempPath),szTempPath); GetTempFileName(szTempPath, L"svn", 0, szErr); // setup redirection handles // output handle must be WRITE mode, share READ // redirect handle must be READ mode, share WRITE hErr = CreateFile(szErr, GENERIC_WRITE, FILE_SHARE_READ, &sa, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, 0); if (!hErr) { error = CFormatMessageWrapper(); return (DWORD)-1; } hRedir = CreateFile(szErr, GENERIC_READ, FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0); if (!hRedir) { error = CFormatMessageWrapper(); return (DWORD)-1; } GetTempFileName(szTempPath, L"svn", 0, szOutput); hOut = CreateFile(szOutput, GENERIC_WRITE, FILE_SHARE_READ, &sa, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY, 0); if (!hOut) { error = CFormatMessageWrapper(); return (DWORD)-1; } // setup startup info, set std out/err handles // hide window STARTUPINFO si; SecureZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; si.hStdOutput = hOut; si.hStdError = hErr; si.wShowWindow = bShow ? SW_SHOW : SW_HIDE; PROCESS_INFORMATION pi; SecureZeroMemory(&pi, sizeof(pi)); if (!CreateProcess(NULL, cmd.GetBuffer(), NULL, NULL, TRUE, 0, NULL, curDir.IsEmpty() ? NULL : curDir.GetWinPath(), &si, &pi)) { const DWORD err = GetLastError(); // preserve the CreateProcess error error = CFormatMessageWrapper(err); SetLastError(err); cmd.ReleaseBuffer(); return (DWORD)-1; } cmd.ReleaseBuffer(); CloseHandle(pi.hThread); // wait for process to finish, capture redirection and // send it to the parent window/console if (bWait) { DWORD dw; char buf[10*1024]; do { SecureZeroMemory(&buf,sizeof(buf)); while (ReadFile(hRedir, &buf, sizeof(buf)-1, &dw, NULL)) { if (dw == 0) break; error += CString(CStringA(buf,dw)); SecureZeroMemory(&buf,sizeof(buf)); } } while (WaitForSingleObject(pi.hProcess, 100) != WAIT_OBJECT_0); // perform any final flushing while (ReadFile(hRedir, &buf, sizeof(buf)-1, &dw, NULL)) { if (dw == 0) break; error += CString(CStringA(buf, dw)); SecureZeroMemory(&buf,sizeof(buf)); } WaitForSingleObject(pi.hProcess, INFINITE); GetExitCodeProcess(pi.hProcess, &exitcode); } CloseHandle(pi.hProcess); DeleteFile(szOutput); DeleteFile(szErr); return exitcode; }
void RemoveChildrenTest() { CTSVNPathList list; list.AddPath(CTSVNPath(L"c:\\test")); list.AddPath(CTSVNPath(L"c:\\test\\file")); list.AddPath(CTSVNPath(L"c:\\testfile")); list.AddPath(CTSVNPath(L"c:\\parent")); list.AddPath(CTSVNPath(L"c:\\parent\\child")); list.AddPath(CTSVNPath(L"c:\\parent\\child1")); list.AddPath(CTSVNPath(L"c:\\parent\\child2")); ATLASSERT(list.GetCount() == 7); list.RemoveChildren(); ATLTRACE("count = %d\n", list.GetCount()); ATLASSERT(list.GetCount() == 3); list.SortByPathname(); ATLASSERT(list[0].GetWinPathString().Compare(L"c:\\parent") == 0); ATLASSERT(list[1].GetWinPathString().Compare(L"c:\\test") == 0); ATLASSERT(list[2].GetWinPathString().Compare(L"c:\\testfile") == 0); }
bool RenameCommand::Execute() { bool bRet = false; CString filename = cmdLinePath.GetFileOrDirectoryName(); CString basePath = cmdLinePath.GetContainingDirectory().GetWinPathString(); ::SetCurrentDirectory(basePath); // show the rename dialog until the user either cancels or enters a new // name (one that's different to the original name CString sNewName; do { CRenameDlg dlg; dlg.m_name = filename; if (!SVN::PathIsURL(cmdLinePath)) dlg.SetFileSystemAutoComplete(); if (dlg.DoModal() != IDOK) return FALSE; sNewName = dlg.m_name; } while(PathIsRelative(sNewName) && !PathIsURL(sNewName) && (sNewName.IsEmpty() || (sNewName.Compare(filename)==0))); CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": rename file %s to %s\n", (LPCTSTR)cmdLinePath.GetWinPathString(), (LPCTSTR)sNewName); CTSVNPath destinationPath(basePath); if (PathIsRelative(sNewName) && !PathIsURL(sNewName)) destinationPath.AppendPathString(sNewName); else destinationPath.SetFromWin(sNewName); CString sMsg; if (SVN::PathIsURL(cmdLinePath)) { // rename an URL. // Ask for a commit message, then rename directly in // the repository CInputLogDlg input; CString sUUID; SVN svn; svn.GetRepositoryRootAndUUID(cmdLinePath, true, sUUID); input.SetUUID(sUUID); CString sHint; sHint.FormatMessage(IDS_INPUT_MOVE, (LPCTSTR)cmdLinePath.GetSVNPathString(), (LPCTSTR)destinationPath.GetSVNPathString()); input.SetActionText(sHint); if (input.DoModal() == IDOK) { sMsg = input.GetLogMessage(); } else { return FALSE; } } if ((cmdLinePath.IsDirectory())||(pathList.GetCount() > 1)) { // renaming a directory can take a while: use the // progress dialog to show the progress of the renaming // operation. CSVNProgressDlg progDlg; progDlg.SetCommand(CSVNProgressDlg::SVNProgress_Rename); progDlg.SetAutoClose (parser); progDlg.SetPathList(pathList); progDlg.SetUrl(destinationPath.GetWinPathString()); progDlg.SetCommitMessage(sMsg); progDlg.DoModal(); bRet = !progDlg.DidErrorsOccur(); } else { CString sFilemask = cmdLinePath.GetFilename(); int slashpos = 0; // find out up to which char sFilemask and sNewName are identical int minlen = min(sFilemask.GetLength(), sNewName.GetLength()); for (; slashpos < minlen; ++slashpos) { if (sFilemask[slashpos] != sNewName[slashpos]) break; } if (sFilemask.ReverseFind('.') >= slashpos) { while (sFilemask.ReverseFind('.') >= slashpos) sFilemask = sFilemask.Left(sFilemask.ReverseFind('.')); } else sFilemask.Empty(); CString sNewMask = sNewName; if (sNewMask.ReverseFind('.') >= slashpos) { while (sNewMask.ReverseFind('.') >= slashpos) sNewMask = sNewMask.Left(sNewMask.ReverseFind('.')); } else sNewMask.Empty(); CString sRightPartNew = sNewName.Mid(sNewMask.GetLength()); CString sRightPartOld = cmdLinePath.GetFilename().Mid(sFilemask.GetLength()); // if the file extension changed, or the old and new right parts are not the // same then we can not correctly guess the new names of similar files, so // just do the plain rename of the selected file and don't offer to rename similar ones. if (((!sFilemask.IsEmpty()) && (parser.HasKey(L"noquestion"))) || (cmdLinePath.GetFileExtension().Compare(destinationPath.GetFileExtension())!=0) || (sRightPartOld.CompareNoCase(sRightPartNew))) { if (RenameWithReplace(GetExplorerHWND(), CTSVNPathList(cmdLinePath), destinationPath, sMsg)) bRet = true; } else { // when refactoring, multiple files have to be renamed // at once because those files belong together. // e.g. file.aspx, file.aspx.cs, file.aspx.resx CTSVNPathList renlist; CSimpleFileFind filefind(cmdLinePath.GetDirectory().GetWinPathString(), sFilemask+L".*"); while (filefind.FindNextFileNoDots()) { if (!filefind.IsDirectory()) renlist.AddPath(CTSVNPath(filefind.GetFilePath())); } if ((renlist.GetCount() <= 1) || (renlist.GetCount() > 10)) // arbitrary value of ten { // Either no matching files to rename, or way too many of them: // just do the default... if (RenameWithReplace(GetExplorerHWND(), CTSVNPathList(cmdLinePath), destinationPath, sMsg)) { bRet = true; CShellUpdater::Instance().AddPathForUpdate(destinationPath); } } else { std::map<CString, CString> renmap; CString sTemp; CString sRenList; for (int i=0; i<renlist.GetCount(); ++i) { CString sFilename = renlist[i].GetFilename(); CString sNewFilename = sNewMask + sFilename.Mid(sFilemask.GetLength()); sTemp.Format(L"\n%s -> %s", (LPCTSTR)sFilename, (LPCTSTR)sNewFilename); if (!renlist[i].IsEquivalentTo(cmdLinePath)) sRenList += sTemp; renmap[renlist[i].GetWinPathString()] = renlist[i].GetContainingDirectory().GetWinPathString()+L"\\"+sNewFilename; } CString sRenameMultipleQuestion; sRenameMultipleQuestion.Format(IDS_PROC_MULTIRENAME, (LPCTSTR)sRenList); UINT idret = ::MessageBox(GetExplorerHWND(), sRenameMultipleQuestion, L"TortoiseSVN", MB_ICONQUESTION|MB_YESNOCANCEL); if (idret == IDYES) { CProgressDlg progress; progress.SetTitle(IDS_PROC_MOVING); progress.SetTime(true); progress.ShowModeless(CWnd::FromHandle(GetExplorerHWND())); DWORD count = 1; for (std::map<CString, CString>::iterator it=renmap.begin(); it != renmap.end(); ++it) { progress.FormatPathLine(1, IDS_PROC_MOVINGPROG, (LPCTSTR)it->first); progress.FormatPathLine(2, IDS_PROC_CPYMVPROG2, (LPCTSTR)it->second); progress.SetProgress64(count, renmap.size()); if (RenameWithReplace(GetExplorerHWND(), CTSVNPathList(CTSVNPath(it->first)), CTSVNPath(it->second), sMsg)) { bRet = true; CShellUpdater::Instance().AddPathForUpdate(CTSVNPath(it->second)); } } progress.Stop(); } else if (idret == IDNO) { // no, user wants to just rename the file he selected if (RenameWithReplace(GetExplorerHWND(), CTSVNPathList(cmdLinePath), destinationPath, sMsg)) { bRet = true; CShellUpdater::Instance().AddPathForUpdate(destinationPath); } } else if (idret == IDCANCEL) { // nothing } } } } return bRet; }
void GetCommonRootTest() { CTSVNPath pathA (L"C:\\Development\\LogDlg.cpp"); CTSVNPath pathB (L"C:\\Development\\LogDlg.h"); CTSVNPath pathC (L"C:\\Development\\SomeDir\\LogDlg.h"); CTSVNPathList list; list.AddPath(pathA); ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(L"C:\\Development\\LogDlg.cpp")==0); list.AddPath(pathB); ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(L"C:\\Development")==0); list.AddPath(pathC); ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(L"C:\\Development")==0); #ifdef _MFC_VER CString sPathList = L"D:\\Development\\StExBar\\StExBar\\src\\setup\\Setup64.wxs*D:\\Development\\StExBar\\StExBar\\src\\setup\\Setup.wxs*D:\\Development\\StExBar\\SKTimeStamp\\src\\setup\\Setup.wxs*D:\\Development\\StExBar\\SKTimeStamp\\src\\setup\\Setup64.wxs"; list.LoadFromAsteriskSeparatedString(sPathList); ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(L"D:\\Development\\StExBar")==0); sPathList = L"c:\\windows\\explorer.exe*c:\\windows"; list.LoadFromAsteriskSeparatedString(sPathList); ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(L"c:\\windows")==0); sPathList = L"c:\\windows\\*c:\\windows"; list.LoadFromAsteriskSeparatedString(sPathList); ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(L"c:\\windows")==0); sPathList = L"c:\\windows\\system32*c:\\windows\\system"; list.LoadFromAsteriskSeparatedString(sPathList); ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(L"c:\\windows")==0); sPathList = L"c:\\windowsdummy*c:\\windows"; list.LoadFromAsteriskSeparatedString(sPathList); ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(L"c:\\")==0); sPathList = L"https://svn.test.com/appidgd3fbn16y8*https://svn.test.com/appid"; list.LoadFromAsteriskSeparatedString(sPathList); ATLASSERT(list.GetCommonRoot().GetWinPathString().CompareNoCase(L"https:\\\\svn.test.com")==0); #endif }
bool SVNDiff::UnifiedDiff(CTSVNPath& tempfile, const CTSVNPath& url1, const SVNRev& rev1, const CTSVNPath& url2, const SVNRev& rev2, const SVNRev& peg, const CString& options, bool bIgnoreAncestry /* = false */, bool bIgnoreProperties /* = true */) { tempfile = CTempFiles::Instance().GetTempFilePath(m_bRemoveTempFiles, CTSVNPath(L"Test.diff")); bool bIsUrl = !!SVN::PathIsURL(url1); CProgressDlg progDlg; progDlg.SetTitle(IDS_APPNAME); progDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROGRESS_UNIFIEDDIFF))); progDlg.SetTime(false); m_pSVN->SetAndClearProgressInfo(&progDlg); progDlg.ShowModeless(GetHWND()); // find the root of the files CTSVNPathList plist; plist.AddPath(url1); plist.AddPath(url2); CTSVNPath relativeTo = plist.GetCommonRoot(); if (!relativeTo.IsUrl()) { if (!relativeTo.IsDirectory()) relativeTo = relativeTo.GetContainingDirectory(); } if (relativeTo.IsEmpty() && url1.Exists() && url2.IsUrl()) { // the source path exists, i.e. it's a local path, so // use this as the relative url relativeTo = url1.GetDirectory(); } // the 'relativeTo' path must be a path: svn throws an error if it's used for urls. else if ((!url2.IsEquivalentTo(url1) && (relativeTo.IsEquivalentTo(url1) || relativeTo.IsEquivalentTo(url2))) || url1.IsUrl() || url2.IsUrl()) relativeTo.Reset(); if ((!url1.IsEquivalentTo(url2))||((rev1.IsWorking() || rev1.IsBase())&&(rev2.IsWorking() || rev2.IsBase()))) { if (!m_pSVN->Diff(url1, rev1, url2, rev2, relativeTo, svn_depth_infinity, true, false, false, false, false, false, bIgnoreProperties, false, options, bIgnoreAncestry, tempfile)) { progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); m_pSVN->ShowErrorDialog(GetHWND()); return false; } } else { if (!m_pSVN->PegDiff(url1, (peg.IsValid() ? peg : (bIsUrl ? m_headPeg : SVNRev::REV_WC)), rev1, rev2, relativeTo, svn_depth_infinity, true, false, false, false, false, false, bIgnoreProperties, false, options, false, tempfile)) { if (!m_pSVN->Diff(url1, rev1, url2, rev2, relativeTo, svn_depth_infinity, true, false, false, false, false, false, bIgnoreProperties, false, options, false, tempfile)) { progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); m_pSVN->ShowErrorDialog(GetHWND()); return false; } } } if (CAppUtils::CheckForEmptyDiff(tempfile)) { progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); TaskDialog(GetHWND(), AfxGetResourceHandle(), MAKEINTRESOURCE(IDS_APPNAME), MAKEINTRESOURCE(IDS_ERR_ERROROCCURED), MAKEINTRESOURCE(IDS_ERR_EMPTYDIFF), TDCBF_OK_BUTTON, TD_ERROR_ICON, NULL); return false; } progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); return true; }
void CCopyDlg::OnOK() { if (::IsWindow(m_pLogDlg->GetSafeHwnd())&&(m_pLogDlg->IsWindowVisible())) { m_pLogDlg->SendMessage(WM_CLOSE); return; } m_bCancelled = true; // check if the status thread has already finished if ((m_pThread)&&(m_bThreadRunning)) { WaitForSingleObject(m_pThread->m_hThread, 1000); if (m_bThreadRunning) { // we gave the thread a chance to quit. Since the thread didn't // listen to us we have to kill it. TerminateThread(m_pThread->m_hThread, (DWORD)-1); InterlockedExchange(&m_bThreadRunning, FALSE); } } CString id; GetDlgItemText(IDC_BUGID, id); CString sRevText; GetDlgItemText(IDC_COPYREVTEXT, sRevText); if (!m_ProjectProperties.CheckBugID(id)) { ShowEditBalloon(IDC_BUGID, IDS_COMMITDLG_ONLYNUMBERS, IDS_ERR_ERROR, TTI_ERROR); return; } m_sLogMessage = m_cLogMessage.GetText(); if ((m_ProjectProperties.bWarnIfNoIssue) && (id.IsEmpty() && !m_ProjectProperties.HasBugID(m_sLogMessage))) { CTaskDialog taskdlg(CString(MAKEINTRESOURCE(IDS_COMMITDLG_WARNNOISSUE_TASK1)), CString(MAKEINTRESOURCE(IDS_COMMITDLG_WARNNOISSUE_TASK2)), L"TortoiseSVN", 0, TDF_USE_COMMAND_LINKS | TDF_ALLOW_DIALOG_CANCELLATION | TDF_POSITION_RELATIVE_TO_WINDOW | TDF_SIZE_TO_CONTENT); taskdlg.AddCommandControl(1, CString(MAKEINTRESOURCE(IDS_COMMITDLG_WARNNOISSUE_TASK3))); taskdlg.AddCommandControl(2, CString(MAKEINTRESOURCE(IDS_COMMITDLG_WARNNOISSUE_TASK4))); taskdlg.SetCommonButtons(TDCBF_CANCEL_BUTTON); taskdlg.SetDefaultCommandControl(2); taskdlg.SetMainIcon(TD_WARNING_ICON); if (taskdlg.DoModal(m_hWnd) != 1) return; } UpdateData(TRUE); if (GetCheckedRadioButton(IDC_COPYHEAD, IDC_COPYREV) == IDC_COPYHEAD) m_CopyRev = SVNRev(SVNRev::REV_HEAD); else if (GetCheckedRadioButton(IDC_COPYHEAD, IDC_COPYREV) == IDC_COPYWC) m_CopyRev = SVNRev(SVNRev::REV_WC); else m_CopyRev = SVNRev(sRevText); if (!m_CopyRev.IsValid()) { ShowEditBalloon(IDC_COPYREVTEXT, IDS_ERR_INVALIDREV, IDS_ERR_ERROR, TTI_ERROR); return; } CString combourl = m_URLCombo.GetWindowString(); if (combourl.IsEmpty()) combourl = m_URLCombo.GetString(); if ((m_wcURL.CompareNoCase(combourl)==0)&&(m_CopyRev.IsHead())) { CString temp; temp.FormatMessage(IDS_ERR_COPYITSELF, (LPCTSTR)m_wcURL, (LPCTSTR)m_URLCombo.GetString()); ::MessageBox(this->m_hWnd, temp, L"TortoiseSVN", MB_ICONERROR); return; } m_URLCombo.SaveHistory(); m_URL = CPathUtils::CombineUrls(m_repoRoot, m_URLCombo.GetString()); if (!CTSVNPath(m_URL).IsValidOnWindows()) { CString sInfo; sInfo.Format(IDS_WARN_NOVALIDPATH_TASK1, (LPCTSTR)m_URL); CTaskDialog taskdlg(sInfo, CString(MAKEINTRESOURCE(IDS_WARN_NOVALIDPATH_TASK2)), L"TortoiseSVN", 0, TDF_ENABLE_HYPERLINKS | TDF_USE_COMMAND_LINKS | TDF_ALLOW_DIALOG_CANCELLATION | TDF_POSITION_RELATIVE_TO_WINDOW | TDF_SIZE_TO_CONTENT); taskdlg.AddCommandControl(1, CString(MAKEINTRESOURCE(IDS_WARN_NOVALIDPATH_TASK3))); taskdlg.AddCommandControl(2, CString(MAKEINTRESOURCE(IDS_WARN_NOVALIDPATH_TASK4))); taskdlg.SetCommonButtons(TDCBF_CANCEL_BUTTON); taskdlg.SetExpansionArea(CString(MAKEINTRESOURCE(IDS_WARN_NOVALIDPATH_TASK5))); taskdlg.SetDefaultCommandControl(2); taskdlg.SetMainIcon(TD_WARNING_ICON); if (taskdlg.DoModal(m_hWnd) != 1) return; } CStringUtils::WriteAsciiStringToClipboard(m_URL); // now let the bugtraq plugin check the commit message CComPtr<IBugTraqProvider2> pProvider2 = NULL; if (m_BugTraqProvider) { HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2); if (SUCCEEDED(hr)) { ATL::CComBSTR temp; ATL::CComBSTR sourceURL; sourceURL.Attach(m_wcURL.AllocSysString()); ATL::CComBSTR parameters; parameters.Attach(m_bugtraq_association.GetParameters().AllocSysString()); ATL::CComBSTR targetURL; targetURL.Attach(m_URL.AllocSysString()); ATL::CComBSTR commitMessage; commitMessage.Attach(m_sLogMessage.AllocSysString()); CBstrSafeVector pathList(1); pathList.PutElement(0, m_path.GetSVNPathString()); hr = pProvider2->CheckCommit(GetSafeHwnd(), parameters, sourceURL, targetURL, pathList, commitMessage, &temp); if (FAILED(hr)) { OnComError(hr); } else { CString sError = temp == 0 ? L"" : temp; if (!sError.IsEmpty()) { CAppUtils::ReportFailedHook(m_hWnd, sError); return; } } } } CTSVNPathList checkedItems; checkedItems.AddPath(m_path); DWORD exitcode = 0; CString error; CHooks::Instance().SetProjectProperties(m_path, m_ProjectProperties); if (CHooks::Instance().CheckCommit(m_hWnd, checkedItems, m_sLogMessage, exitcode, error)) { if (exitcode) { CString sErrorMsg; sErrorMsg.Format(IDS_HOOK_ERRORMSG, (LPCWSTR)error); CTaskDialog taskdlg(sErrorMsg, CString(MAKEINTRESOURCE(IDS_HOOKFAILED_TASK2)), L"TortoiseSVN", 0, TDF_ENABLE_HYPERLINKS | TDF_USE_COMMAND_LINKS | TDF_ALLOW_DIALOG_CANCELLATION | TDF_POSITION_RELATIVE_TO_WINDOW | TDF_SIZE_TO_CONTENT); taskdlg.AddCommandControl(1, CString(MAKEINTRESOURCE(IDS_HOOKFAILED_TASK3))); taskdlg.AddCommandControl(2, CString(MAKEINTRESOURCE(IDS_HOOKFAILED_TASK4))); taskdlg.SetDefaultCommandControl(1); taskdlg.SetMainIcon(TD_ERROR_ICON); bool retry = (taskdlg.DoModal(GetSafeHwnd()) == 1); if (retry) return; } } if (!m_sLogMessage.IsEmpty()) { m_History.AddEntry(m_sLogMessage); m_History.Save(); } m_sBugID.Trim(); if (!m_sBugID.IsEmpty()) { m_sBugID.Replace(L", ", L","); m_sBugID.Replace(L" ,", L","); CString sBugID = m_ProjectProperties.sMessage; sBugID.Replace(L"%BUGID%", m_sBugID); if (m_ProjectProperties.bAppend) m_sLogMessage += L"\n" + sBugID + L"\n"; else m_sLogMessage = sBugID + L"\n" + m_sLogMessage; UpdateData(FALSE); } CResizableStandAloneDialog::OnOK(); }
void CHooks::AddPathParam(CString& sCmd, const CTSVNPathList& pathList) { CTSVNPath temppath = CTempFiles::Instance().GetTempFilePath(true); pathList.WriteToFile(temppath.GetWinPathString(), true); AddParam(sCmd, temppath.GetWinPathString()); }
void CSVNLogQuery::Log ( const CTSVNPathList& targets , const SVNRev& peg_revision , const SVNRev& start , const SVNRev& end , int limit , bool strictNodeHistory , ILogReceiver* receiver , bool includeChanges , bool includeMerges , bool includeStandardRevProps , bool includeUserRevProps , const TRevPropNames& userRevProps) { SVNPool localpool (pool); // construct parameters: // everything we need to relay the result to the receiver SBaton baton = { receiver , includeChanges , includeStandardRevProps , includeUserRevProps}; // list of revision ranges to fetch // (as of now, there is only one such range) svn_opt_revision_range_t revision_range = {*start, *end}; apr_array_header_t* revision_ranges = apr_array_make (localpool, 1, sizeof(apr_array_header_t*)); *(svn_opt_revision_range_t**)apr_array_push (revision_ranges) = &revision_range; // build list of revprops to fetch. Fetch all of them // if all user-revprops are requested but no std-revprops // (post-filter before them passing to the receiver) apr_array_header_t* revprops = NULL; if (includeStandardRevProps) { // fetch user rev-props? if (includeUserRevProps) { // fetch some but not all user rev-props? if (!userRevProps.empty()) { revprops = apr_array_make ( localpool , (int)GetStandardRevProps().size() + (int)userRevProps.size() , sizeof(const char *)); AppendStrings (localpool, revprops, GetStandardRevProps()); AppendStrings (localpool, revprops, userRevProps); } } else { // standard revprops only revprops = apr_array_make ( localpool , (int)GetStandardRevProps().size() , sizeof(const char *)); AppendStrings (localpool, revprops, GetStandardRevProps()); } } else { // fetch some but not all user rev-props? if (includeUserRevProps && !userRevProps.empty()) { revprops = apr_array_make ( localpool , (int)userRevProps.size() , sizeof(const char *)); AppendStrings (localpool, revprops, userRevProps); } } CHooks::Instance().PreConnect(targets); SVNTRACE ( svn_error_t *result = svn_client_log5 ( targets.MakePathArray (localpool) , peg_revision , revision_ranges , limit , includeChanges , strictNodeHistory , includeMerges , revprops , LogReceiver , (void *)&baton , context , localpool), NULL ); if (result != NULL) throw SVNError (result); }
bool RenameCommand::Execute() { bool bRet = false; CString filename = cmdLinePath.GetFileOrDirectoryName(); CString basePath = cmdLinePath.GetContainingDirectory().GetGitPathString(); //::SetCurrentDirectory(basePath); // show the rename dialog until the user either cancels or enters a new // name (one that's different to the original name CString sNewName; do { CRenameDlg dlg; dlg.m_name = filename; if (dlg.DoModal() != IDOK) return FALSE; sNewName = dlg.m_name; } while(PathIsRelative(sNewName) && !PathIsURL(sNewName) && (sNewName.IsEmpty() || (sNewName.Compare(filename)==0))); if(!basePath.IsEmpty()) sNewName=basePath+"/"+sNewName; CString cmd; CString output; cmd.Format(_T("git.exe mv -- \"%s\" \"%s\""), cmdLinePath.GetGitPathString(), sNewName); if(g_Git.Run(cmd,&output,CP_ACP)) { CMessageBox::Show(hwndExplorer, output, _T("TortoiseGit"), MB_OK); } CTGitPath newpath; newpath.SetFromGit(sNewName); CShellUpdater::Instance().AddPathForUpdate(newpath); #if 0 TRACE(_T("rename file %s to %s\n"), (LPCTSTR)cmdLinePath.GetWinPathString(), (LPCTSTR)sNewName); CTSVNPath destinationPath(basePath); if (PathIsRelative(sNewName) && !PathIsURL(sNewName)) destinationPath.AppendPathString(sNewName); else destinationPath.SetFromWin(sNewName); // check if a rename just with case is requested: that's not possible on windows file systems // and we have to show an error. if (cmdLinePath.GetWinPathString().CompareNoCase(destinationPath.GetWinPathString())==0) { //rename to the same file! CString sHelpPath = theApp.m_pszHelpFilePath; sHelpPath += _T("::/tsvn-dug-rename.html#tsvn-dug-renameincase"); CMessageBox::Show(hwndExplorer, IDS_PROC_CASERENAME, IDS_APPNAME, MB_OK|MB_HELP, sHelpPath); } else { CString sMsg; if (SVN::PathIsURL(cmdLinePath)) { // rename an URL. // Ask for a commit message, then rename directly in // the repository CInputLogDlg input; CString sUUID; SVN svn; svn.GetRepositoryRootAndUUID(cmdLinePath, sUUID); input.SetUUID(sUUID); CString sHint; sHint.Format(IDS_INPUT_MOVE, (LPCTSTR)cmdLinePath.GetSVNPathString(), (LPCTSTR)destinationPath.GetSVNPathString()); input.SetActionText(sHint); if (input.DoModal() == IDOK) { sMsg = input.GetLogMessage(); } else { return FALSE; } } if ((cmdLinePath.IsDirectory())||(pathList.GetCount() > 1)) { // renaming a directory can take a while: use the // progress dialog to show the progress of the renaming // operation. CSVNProgressDlg progDlg; progDlg.SetCommand(CSVNProgressDlg::SVNProgress_Rename); if (parser.HasVal(_T("closeonend"))) progDlg.SetAutoClose(parser.GetLongVal(_T("closeonend"))); progDlg.SetPathList(pathList); progDlg.SetUrl(destinationPath.GetWinPathString()); progDlg.SetCommitMessage(sMsg); progDlg.SetRevision(SVNRev::REV_WC); progDlg.DoModal(); bRet = !progDlg.DidErrorsOccur(); } else { SVN svn; CString sFilemask = cmdLinePath.GetFilename(); if (sFilemask.ReverseFind('.')>=0) { sFilemask = sFilemask.Left(sFilemask.ReverseFind('.')); } else sFilemask.Empty(); CString sNewMask = sNewName; if (sNewMask.ReverseFind('.'>=0)) { sNewMask = sNewMask.Left(sNewMask.ReverseFind('.')); } else sNewMask.Empty(); if (((!sFilemask.IsEmpty()) && (parser.HasKey(_T("noquestion")))) || (cmdLinePath.GetFileExtension().Compare(destinationPath.GetFileExtension())!=0)) { if (!svn.Move(CTSVNPathList(cmdLinePath), destinationPath, TRUE, sMsg)) { TRACE(_T("%s\n"), (LPCTSTR)svn.GetLastErrorMessage()); CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR); } else bRet = true; } else { // when refactoring, multiple files have to be renamed // at once because those files belong together. // e.g. file.aspx, file.aspx.cs, file.aspx.resx CTSVNPathList renlist; CSimpleFileFind filefind(cmdLinePath.GetDirectory().GetWinPathString(), sFilemask+_T(".*")); while (filefind.FindNextFileNoDots()) { if (!filefind.IsDirectory()) renlist.AddPath(CTSVNPath(filefind.GetFilePath())); } if (renlist.GetCount()<=1) { // we couldn't find any other matching files // just do the default... if (!svn.Move(CTSVNPathList(cmdLinePath), destinationPath, TRUE, sMsg)) { TRACE(_T("%s\n"), (LPCTSTR)svn.GetLastErrorMessage()); CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR); } else { bRet = true; CShellUpdater::Instance().AddPathForUpdate(destinationPath); } } else { std::map<CString, CString> renmap; CString sTemp; CString sRenList; for (int i=0; i<renlist.GetCount(); ++i) { CString sFilename = renlist[i].GetFilename(); CString sNewFilename = sNewMask + sFilename.Mid(sFilemask.GetLength()); sTemp.Format(_T("\n%s -> %s"), (LPCTSTR)sFilename, (LPCTSTR)sNewFilename); if (!renlist[i].IsEquivalentTo(cmdLinePath)) sRenList += sTemp; renmap[renlist[i].GetWinPathString()] = renlist[i].GetContainingDirectory().GetWinPathString()+_T("\\")+sNewFilename; } CString sRenameMultipleQuestion; sRenameMultipleQuestion.Format(IDS_PROC_MULTIRENAME, (LPCTSTR)sRenList); UINT idret = CMessageBox::Show(hwndExplorer, sRenameMultipleQuestion, _T("TortoiseGit"), MB_ICONQUESTION|MB_YESNOCANCEL); if (idret == IDYES) { CProgressDlg progress; progress.SetTitle(IDS_PROC_MOVING); progress.SetAnimation(IDR_MOVEANI); progress.SetTime(true); progress.ShowModeless(CWnd::FromHandle(hwndExplorer)); DWORD count = 1; for (std::map<CString, CString>::iterator it=renmap.begin(); it != renmap.end(); ++it) { progress.FormatPathLine(1, IDS_PROC_MOVINGPROG, (LPCTSTR)it->first); progress.FormatPathLine(2, IDS_PROC_CPYMVPROG2, (LPCTSTR)it->second); progress.SetProgress(count, renmap.size()); if (!svn.Move(CTSVNPathList(CTSVNPath(it->first)), CTSVNPath(it->second), TRUE, sMsg)) { if (svn.Err->apr_err == SVN_ERR_ENTRY_NOT_FOUND) { bRet = !!MoveFile(it->first, it->second); } else { TRACE(_T("%s\n"), (LPCTSTR)svn.GetLastErrorMessage()); CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR); bRet = false; } } else { bRet = true; CShellUpdater::Instance().AddPathForUpdate(CTSVNPath(it->second)); } } progress.Stop(); } else if (idret == IDNO) { // no, user wants to just rename the file he selected if (!svn.Move(CTSVNPathList(cmdLinePath), destinationPath, TRUE, sMsg)) { TRACE(_T("%s\n"), (LPCTSTR)svn.GetLastErrorMessage()); CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR); } else { bRet = true; CShellUpdater::Instance().AddPathForUpdate(destinationPath); } } else if (idret == IDCANCEL) { // nothing } } } } } #endif CShellUpdater::Instance().Flush(); return bRet; }