void SubversionPathTest() { CTSVNPath testPath; testPath.SetFromWin(L"c:\\"); ATLASSERT(strcmp(testPath.GetSVNApiPath(pool), "C:/") == 0); testPath.SetFromWin(L"c:\\folder"); ATLASSERT(strcmp(testPath.GetSVNApiPath(pool), "C:/folder") == 0); testPath.SetFromWin(L"c:\\a\\b\\c\\d\\e"); ATLASSERT(strcmp(testPath.GetSVNApiPath(pool), "C:/a/b/c/d/e") == 0); testPath.SetFromUnknown(L"http://testing/"); ATLASSERT(strcmp(testPath.GetSVNApiPath(pool), "http://testing") == 0); testPath.SetFromSVN(NULL); ATLASSERT(strlen(testPath.GetSVNApiPath(pool))==0); testPath.SetFromWin(L"\\\\a\\b\\c\\d\\e"); ATLASSERT(strcmp(testPath.GetSVNApiPath(pool), "//a/b/c/d/e") == 0); testPath.SetFromWin(L"\\\\?\\C:\\Windows"); ATLASSERT(wcscmp(testPath.GetWinPath(), L"C:\\Windows")==0); testPath.SetFromUnknown(L"\\\\?\\C:\\Windows"); ATLASSERT(wcscmp(testPath.GetWinPath(), L"C:\\Windows")==0); #if defined(_MFC_VER) testPath.SetFromUnknown(L"http://testing again"); ATLASSERT(strcmp(testPath.GetSVNApiPath(pool), "http://testing%20again") == 0); testPath.SetFromUnknown(L"http://testing%20again"); ATLASSERT(strcmp(testPath.GetSVNApiPath(pool), "http://testing%20again") == 0); testPath.SetFromUnknown(L"http://testing special chars \344\366\374"); ATLASSERT(strcmp(testPath.GetSVNApiPath(pool), "http://testing%20special%20chars%20%c3%a4%c3%b6%c3%bc") == 0); #endif }
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 CSVNStatusCache::BlockPath(const CTSVNPath& path, bool specific, ULONGLONG timeout /* = 0 */) { if (timeout == 0) timeout = BLOCK_PATH_DEFAULT_TIMEOUT; if (timeout > BLOCK_PATH_MAX_TIMEOUT) timeout = BLOCK_PATH_MAX_TIMEOUT; timeout = GetTickCount64() + (timeout * 1000); // timeout is in seconds, but we need the milliseconds if (!specific) { CTSVNPath p(path); do { CTSVNPath dbPath(p); dbPath.AppendPathString(g_SVNAdminDir.GetAdminDirName() + L"\\wc.db"); if (!dbPath.Exists()) p = p.GetContainingDirectory(); else { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": block path %s\n", p.GetWinPath()); AutoLocker lock(m_NoWatchPathCritSec); m_NoWatchPaths[p] = timeout; return true; } } while (!p.IsEmpty()); } CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": block path %s\n", path.GetWinPath()); AutoLocker lock(m_NoWatchPathCritSec); m_NoWatchPaths[path.GetDirectory()] = timeout; return true; }
void CHooks::AddErrorParam(CString& sCmd, const CString& error) { CTSVNPath tempPath; tempPath = CTempFiles::Instance().GetTempFilePath(true); CStringUtils::WriteStringToTextFile(tempPath.GetWinPath(), (LPCTSTR)error); AddParam(sCmd, tempPath.GetWinPathString()); }
bool CTSVNPathList::LoadFromFile(const CTSVNPath& filename) { Clear(); try { CString strLine; CStdioFile file(filename.GetWinPath(), CFile::typeBinary | CFile::modeRead | CFile::shareDenyWrite); // for every selected file/folder CTSVNPath path; while (file.ReadString(strLine)) { path.SetFromUnknown(strLine); AddPath(path); } file.Close(); } catch (CFileException* pE) { std::unique_ptr<TCHAR[]> error(new TCHAR[10000]); pE->GetErrorMessage(error.get(), 10000); ::MessageBox(NULL, error.get(), L"TortoiseSVN", MB_ICONERROR); pE->Delete(); return false; } return true; }
CTSVNPath CHooks::AddMessageFileParam(CString& sCmd, const CString& message) { CTSVNPath tempPath; tempPath = CTempFiles::Instance().GetTempFilePath(true); CStringUtils::WriteStringToTextFile(tempPath.GetWinPath(), (LPCTSTR)message); AddParam(sCmd, tempPath.GetWinPathString()); return tempPath; }
CStatusCacheEntry CSVNStatusCache::GetStatusForPath(const CTSVNPath& path, DWORD flags, bool bFetch /* = true */) { bool bRecursive = !!(flags & TSVNCACHE_FLAGS_RECUSIVE_STATUS); // Check a very short-lived 'mini-cache' of the last thing we were asked for. long now = (long)GetTickCount(); if(now-m_mostRecentExpiresAt < 0) { if(path.IsEquivalentToWithoutCase(m_mostRecentAskedPath)) { return m_mostRecentStatus; } } { AutoLocker lock(m_critSec); m_mostRecentAskedPath = path; m_mostRecentExpiresAt = now+1000; } if (IsPathGood(path) && m_shellCache.IsPathAllowed(path.GetWinPath())) { // Stop the crawler starting on a new folder while we're doing this much more important task... // Please note, that this may be a second "lock" used concurrently to the one in RemoveCacheForPath(). CCrawlInhibitor crawlInhibit(&m_folderCrawler); CTSVNPath dirpath = path.GetContainingDirectory(); if (dirpath.IsEmpty()) dirpath = path.GetDirectory(); CCachedDirectory * cachedDir = GetDirectoryCacheEntry(dirpath); if (cachedDir != NULL) { CStatusCacheEntry entry = cachedDir->GetStatusForMember(path, bRecursive, bFetch); { AutoLocker lock(m_critSec); m_mostRecentStatus = entry; return m_mostRecentStatus; } } cachedDir = GetDirectoryCacheEntry(path.GetDirectory()); if (cachedDir != NULL) { CStatusCacheEntry entry = cachedDir->GetStatusForMember(path, bRecursive, bFetch); { AutoLocker lock(m_critSec); m_mostRecentStatus = entry; return m_mostRecentStatus; } } } AutoLocker lock(m_critSec); m_mostRecentStatus = CStatusCacheEntry(); if (m_shellCache.ShowExcludedAsNormal() && path.IsDirectory() && m_shellCache.HasSVNAdminDir(path.GetWinPath(), true)) { m_mostRecentStatus.ForceStatus(svn_wc_status_normal); } return m_mostRecentStatus; }
CCachedDirectory::CCachedDirectory(const CTSVNPath& directoryPath) : m_wcDbFileTime(0) , m_bCurrentFullStatusValid(false) , m_currentFullStatus(svn_wc_status_none) , m_mostImportantFileStatus(svn_wc_status_none) , m_pCtx(NULL) , m_FetchingStatus(FALSE) { ATLASSERT(directoryPath.IsDirectory() || !PathFileExists(directoryPath.GetWinPath())); m_directoryPath = directoryPath; }
LRESULT CUnlockDlg::OnFileDropped(WPARAM, LPARAM lParam) { BringWindowToTop(); SetForegroundWindow(); SetActiveWindow(); // if multiple files/folders are dropped // this handler is called for every single item // separately. // To avoid creating multiple refresh threads and // causing crashes, we only add the items to the // list control and start a timer. // When the timer expires, we start the refresh thread, // but only if it isn't already running - otherwise we // restart the timer. CTSVNPath path; path.SetFromWin((LPCTSTR)lParam); if (!m_unlockListCtrl.HasPath(path)) { if (m_pathList.AreAllPathsFiles()) { m_pathList.AddPath(path); m_pathList.RemoveDuplicates(); } else { // if the path list contains folders, we have to check whether // our just (maybe) added path is a child of one of those. If it is // a child of a folder already in the list, we must not add it. Otherwise // that path could show up twice in the list. bool bHasParentInList = false; for (int i=0; i<m_pathList.GetCount(); ++i) { if (m_pathList[i].IsAncestorOf(path)) { bHasParentInList = true; break; } } if (!bHasParentInList) { m_pathList.AddPath(path); m_pathList.RemoveDuplicates(); } } } // Always start the timer, since the status of an existing item might have changed SetTimer(REFRESHTIMER, 200, NULL); ATLTRACE(_T("Item %s dropped, timer started\n"), path.GetWinPath()); return 0; }
void CRepoCreationFinished::OnBnClickedCreatefolders() { // create the default folder structure in a temp folder CTSVNPath tempDir = CTempFiles::Instance().GetTempDirPath(true); if (tempDir.IsEmpty()) { ::MessageBox(m_hWnd, CString(MAKEINTRESOURCE(IDS_ERR_CREATETEMPDIR)), CString(MAKEINTRESOURCE(IDS_APPNAME)), MB_ICONERROR); return; } CTSVNPath tempDirSub = tempDir; tempDirSub.AppendPathString(L"trunk"); CreateDirectory(tempDirSub.GetWinPath(), NULL); tempDirSub = tempDir; tempDirSub.AppendPathString(L"branches"); CreateDirectory(tempDirSub.GetWinPath(), NULL); tempDirSub = tempDir; tempDirSub.AppendPathString(L"tags"); CreateDirectory(tempDirSub.GetWinPath(), NULL); CString url; if (m_RepoPath.GetWinPathString().GetAt(0) == '\\') // starts with '\' means an UNC path { CString p = m_RepoPath.GetWinPathString(); p.TrimLeft('\\'); url = L"file://"+p; } else url = L"file:///"+m_RepoPath.GetWinPathString(); // import the folder structure into the new repository SVN svn; if (!svn.Import(tempDir, CTSVNPath(url), CString(MAKEINTRESOURCE(IDS_MSG_IMPORTEDSTRUCTURE)), NULL, svn_depth_infinity, true, true, false)) { svn.ShowErrorDialog(m_hWnd); return; } MessageBox(CString(MAKEINTRESOURCE(IDS_MSG_IMPORTEDSTRUCTUREFINISHED)), L"TortoiseSVN", MB_ICONINFORMATION); DialogEnableWindow(IDC_CREATEFOLDERS, FALSE); }
CString PasteMoveCommand::Validate( const int /*nID*/, const CString& input ) { CString sError; CTSVNPath p = m_renPath.GetContainingDirectory(); p.AppendPathString(input); if (input.IsEmpty()) sError.LoadString(IDS_ERR_NOVALIDPATH); else if (PathFileExists(p.GetWinPath())) sError.LoadString(IDS_ERR_FILEEXISTS); return sError; }
CStatusCacheEntry CCachedDirectory::GetStatusForMember(const CTSVNPath& path, bool bRecursive, bool bFetch /* = true */) { CStringA strCacheKey; bool bThisDirectoryIsUnversioned = false; bool bRequestForSelf = false; if(path.IsEquivalentToWithoutCase(m_directoryPath)) { bRequestForSelf = true; } // In all most circumstances, we ask for the status of a member of this directory. ATLASSERT(m_directoryPath.IsEquivalentToWithoutCase(path.GetContainingDirectory()) || bRequestForSelf); long long dbFileTime = CSVNStatusCache::Instance().WCRoots()->GetDBFileTime(m_directoryPath); bool wcDbFileTimeChanged = (m_wcDbFileTime != dbFileTime); if ( !wcDbFileTimeChanged ) { if(m_wcDbFileTime == 0) { // We are a folder which is not in a working copy bThisDirectoryIsUnversioned = true; m_ownStatus.SetStatus(NULL, false, false); // If a user removes the .svn directory, we get here with m_entryCache // not being empty, but still us being unversioned if (!m_entryCache.empty()) { m_entryCache.clear(); } ATLASSERT(m_entryCache.empty()); // However, a member *DIRECTORY* might be the top of WC // so we need to ask them to get their own status if(!path.IsDirectory()) { if ((PathFileExists(path.GetWinPath()))||(bRequestForSelf)) return CStatusCacheEntry(); // the entry doesn't exist anymore! // but we can't remove it from the cache here: // the GetStatusForMember() method is called only with a read // lock and not a write lock! // So mark it for crawling, and let the crawler remove it // later CSVNStatusCache::Instance().AddFolderForCrawling(path.GetContainingDirectory()); return CStatusCacheEntry(); } else { // If we're in the special case of a directory being asked for its own status // and this directory is unversioned, then we should just return that here if(bRequestForSelf) { return CStatusCacheEntry(); } } } if (CSVNStatusCache::Instance().GetDirectoryCacheEntryNoCreate(path) != NULL) { // We don't have directory status in our cache // Ask the directory if it knows its own status CCachedDirectory * dirEntry = CSVNStatusCache::Instance().GetDirectoryCacheEntry(path); if ((dirEntry)&&(dirEntry->IsOwnStatusValid())) { // To keep recursive status up to date, we'll request that children are all crawled again // We have to do this because the directory watcher isn't very reliable (especially under heavy load) // and also has problems with SUBSTed drives. // If nothing has changed in those directories, this crawling is fast and only // accesses two files for each directory. if (bRecursive) { AutoLocker lock(dirEntry->m_critSec); ChildDirStatus::const_iterator it; for(it = dirEntry->m_childDirectories.begin(); it != dirEntry->m_childDirectories.end(); ++it) { CTSVNPath newpath; CString winPath = CUnicodeUtils::GetUnicode (it->first); newpath.SetFromWin(winPath, true); CSVNStatusCache::Instance().AddFolderForCrawling(newpath); } } return dirEntry->GetOwnStatus(bRecursive); } } else { { // if we currently are fetching the status of the directory // we want the status for, we just return an empty entry here // and don't wait for that fetching to finish. // That's because fetching the status can take a *really* long // time (e.g. if a commit is also in progress on that same // directory), and we don't want to make the explorer appear // to hang. if ((!bFetch)&&(m_FetchingStatus)) { if (m_directoryPath.IsAncestorOf(path)) { m_currentFullStatus = m_mostImportantFileStatus = svn_wc_status_none; return GetCacheStatusForMember(path); } } } // Look up a file in our own cache AutoLocker lock(m_critSec); strCacheKey = GetCacheKey(path); CacheEntryMap::iterator itMap = m_entryCache.find(strCacheKey); if(itMap != m_entryCache.end()) { // We've hit the cache - check for timeout if(!itMap->second.HasExpired((long)GetTickCount())) { if(itMap->second.DoesFileTimeMatch(path.GetLastWriteTime())) { if ((itMap->second.GetEffectiveStatus()!=svn_wc_status_missing)||(!PathFileExists(path.GetWinPath()))) { // Note: the filetime matches after a modified has been committed too. // So in that case, we would return a wrong status (e.g. 'modified' instead // of 'normal') here. return itMap->second; } } } } } } else { if ((!bFetch)&&(m_FetchingStatus)) { if (m_directoryPath.IsAncestorOf(path)) { // returning empty status (status fetch in progress) // also set the status to 'none' to have the status change and // the shell updater invoked in the crawler m_currentFullStatus = m_mostImportantFileStatus = svn_wc_status_none; CSVNStatusCache::Instance().AddFolderForCrawling(m_directoryPath.GetDirectory()); return GetCacheStatusForMember(path); } } // if we're fetching the status for the explorer, // we don't refresh the status but use the one // we already have (to save time and make the explorer // more responsive in stress conditions). // We leave the refreshing to the crawler. if ((!bFetch)&&(m_wcDbFileTime)) { CSVNStatusCache::Instance().AddFolderForCrawling(m_directoryPath.GetDirectory()); return GetCacheStatusForMember(path); } AutoLocker lock(m_critSec); m_entryCache.clear(); strCacheKey = GetCacheKey(path); } // We've not got this item in the cache - let's add it // We never bother asking SVN for the status of just one file, always for its containing directory if (g_SVNAdminDir.IsAdminDirPath(path.GetWinPathString())) { // We're being asked for the status of an .SVN directory // It's not worth asking for this return CStatusCacheEntry(); } { if ((!bFetch)&&(m_FetchingStatus)) { if (m_directoryPath.IsAncestorOf(path)) { m_currentFullStatus = m_mostImportantFileStatus = svn_wc_status_none; return GetCacheStatusForMember(path); } } } { AutoLocker lock(m_critSec); m_mostImportantFileStatus = svn_wc_status_none; m_childDirectories.clear(); m_entryCache.clear(); m_ownStatus.SetStatus(NULL, false, false); } if(!bThisDirectoryIsUnversioned) { if (!SvnUpdateMembersStatus()) { m_wcDbFileTime = 0; return CStatusCacheEntry(); } } // Now that we've refreshed our SVN status, we can see if it's // changed the 'most important' status value for this directory. // If it has, then we should tell our parent UpdateCurrentStatus(); m_wcDbFileTime = dbFileTime; if (path.IsDirectory()) { CCachedDirectory * dirEntry = CSVNStatusCache::Instance().GetDirectoryCacheEntry(path); if ((dirEntry)&&(dirEntry->IsOwnStatusValid())) { //CSVNStatusCache::Instance().AddFolderForCrawling(path); return dirEntry->GetOwnStatus(bRecursive); } // If the status *still* isn't valid here, it means that // the current directory is unversioned, and we shall need to ask its children for info about themselves if ((dirEntry)&&(dirEntry != this)) return dirEntry->GetStatusForMember(path,bRecursive); // add the path for crawling: if it's really unversioned, the crawler will // only check for the admin dir and do nothing more. But if it is // versioned (could happen in a nested layout) the crawler will update its // status correctly CSVNStatusCache::Instance().AddFolderForCrawling(path); return CStatusCacheEntry(); } else { CacheEntryMap::iterator itMap = m_entryCache.find(strCacheKey); if(itMap != m_entryCache.end()) { return itMap->second; } } AddEntry(path, NULL, false, false); return CStatusCacheEntry(); }
void CShellUpdater::WorkerThread() { HANDLE hWaitHandles[2]; hWaitHandles[0] = m_hTerminationEvent; hWaitHandles[1] = m_hWakeEvent; for(;;) { DWORD waitResult = WaitForMultipleObjects(_countof(hWaitHandles), hWaitHandles, FALSE, INFINITE); // exit event/working loop if the first event (m_hTerminationEvent) // has been signaled or if one of the events has been abandoned // (i.e. ~CShellUpdater() is being executed) if(waitResult == WAIT_OBJECT_0 || waitResult == WAIT_ABANDONED_0 || waitResult == WAIT_ABANDONED_0+1) { // Termination event break; } // wait some time before we notify the shell Sleep(50); for(;;) { CTSVNPath workingPath; if (!m_bRunning) return; Sleep(0); { AutoLocker lock(m_critSec); if(m_pathsToUpdate.empty()) { // Nothing left to do break; } if(InterlockedExchange(&m_bItemsAddedSinceLastUpdate, FALSE)) { m_pathsToUpdate.erase(std::unique(m_pathsToUpdate.begin(), m_pathsToUpdate.end(), &CTSVNPath::PredLeftEquivalentToRight), m_pathsToUpdate.end()); } workingPath = m_pathsToUpdate.front(); m_pathsToUpdate.pop_front(); } if (workingPath.IsEmpty()) continue; CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": shell notification for %s\n", workingPath.GetWinPath()); if (workingPath.IsDirectory()) { // first send a notification about a sub folder change, so explorer doesn't discard // the folder notification. Since we only know for sure that the subversion admin // dir is present, we send a notification for that folder. CString admindir = workingPath.GetWinPathString() + L"\\" + g_SVNAdminDir.GetAdminDirName(); SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH | SHCNF_FLUSHNOWAIT, (LPCTSTR)admindir, NULL); SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH | SHCNF_FLUSHNOWAIT, workingPath.GetWinPath(), NULL); // Sending an UPDATEDIR notification somehow overwrites/deletes the UPDATEITEM message. And without // that message, the folder overlays in the current view don't get updated without hitting F5. // Drawback is, without UPDATEDIR, the left tree view isn't always updated... //SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_PATH | SHCNF_FLUSHNOWAIT, workingPath.GetWinPath(), NULL); } else SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH | SHCNF_FLUSHNOWAIT, workingPath.GetWinPath(), NULL); } } _endthread(); }
bool SyncCommand::Execute() { bool bRet = false; CRegString rSyncPath(L"Software\\TortoiseSVN\\SyncPath"); CTSVNPath syncPath = CTSVNPath(CString(rSyncPath)); CTSVNPath syncFolder = syncPath; CRegDWORD regCount(L"Software\\TortoiseSVN\\SyncCounter"); CRegDWORD regSyncAuth(L"Software\\TortoiseSVN\\SyncAuth"); bool bSyncAuth = DWORD(regSyncAuth) != 0; if (!cmdLinePath.IsEmpty()) syncPath = cmdLinePath; if (syncPath.IsEmpty() && !parser.HasKey(L"askforpath")) { return false; } syncPath.AppendPathString(L"tsvnsync.tsex"); BOOL bWithLocals = FALSE; if (parser.HasKey(L"askforpath")) { // ask for the path first, then for the password // this is used for a manual import/export CString path; bool bGotPath = FileOpenSave(path, bWithLocals, !!parser.HasKey(L"load"), GetExplorerHWND()); if (bGotPath) { syncPath = CTSVNPath(path); if (!parser.HasKey(L"load") && syncPath.GetFileExtension().IsEmpty()) syncPath.AppendRawString(L".tsex"); } else return false; } CSimpleIni iniFile; iniFile.SetMultiLine(true); SVNAuthData authData; CAutoRegKey hMainKey; RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\TortoiseSVN", 0, KEY_READ, hMainKey.GetPointer()); FILETIME filetime = { 0 }; RegQueryInfoKey(hMainKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &filetime); bool bCloudIsNewer = false; if (!parser.HasKey(L"save")) { // open the file in read mode CAutoFile hFile = CreateFile(syncPath.GetWinPathString(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile.IsValid()) { // load the file LARGE_INTEGER fsize = { 0 }; if (GetFileSizeEx(hFile, &fsize)) { auto filebuf = std::make_unique<char[]>(DWORD(fsize.QuadPart)); DWORD bytesread = 0; if (ReadFile(hFile, filebuf.get(), DWORD(fsize.QuadPart), &bytesread, NULL)) { // decrypt the file contents std::string encrypted; if (bytesread > 0) encrypted = std::string(filebuf.get(), bytesread); CRegString regPW(L"Software\\TortoiseSVN\\SyncPW"); CString password; if (parser.HasKey(L"askforpath") && parser.HasKey(L"load")) { INT_PTR dlgret = 0; bool bPasswordMatches = true; do { bPasswordMatches = true; CPasswordDlg passDlg(CWnd::FromHandle(GetExplorerHWND())); passDlg.m_bForSave = !!parser.HasKey(L"save"); dlgret = passDlg.DoModal(); password = passDlg.m_sPW1; if ((dlgret == IDOK) && (parser.HasKey(L"load"))) { std::string passworda = CUnicodeUtils::StdGetUTF8((LPCWSTR)password); std::string decrypted = CStringUtils::Decrypt(encrypted, passworda); if ((decrypted.size() < 3) || (decrypted.substr(0, 3) != "***")) { bPasswordMatches = false; } } } while ((dlgret == IDOK) && !bPasswordMatches); if (dlgret != IDOK) return false; } else { auto passwordbuf = CStringUtils::Decrypt(CString(regPW)); if (passwordbuf.get()) { password = passwordbuf.get(); } else { // password does not match or it couldn't be read from // the registry! // TaskDialog(GetExplorerHWND(), AfxGetResourceHandle(), MAKEINTRESOURCE(IDS_APPNAME), MAKEINTRESOURCE(IDS_ERR_ERROROCCURED), MAKEINTRESOURCE(IDS_SYNC_WRONGPASSWORD), TDCBF_OK_BUTTON, TD_ERROR_ICON, NULL); CString sCmd = L" /command:settings /page:21"; CAppUtils::RunTortoiseProc(sCmd); return false; } } std::string passworda = CUnicodeUtils::StdGetUTF8((LPCWSTR)password); std::string decrypted = CStringUtils::Decrypt(encrypted, passworda); if (decrypted.size() >= 3) { if (decrypted.substr(0, 3) == "***") { decrypted = decrypted.substr(3); // pass the decrypted data to the ini file iniFile.LoadFile(decrypted.c_str(), decrypted.size()); int inicount = _wtoi(iniFile.GetValue(L"sync", L"synccounter", L"")); if (inicount != 0) { if (int(DWORD(regCount)) < inicount) { bCloudIsNewer = true; regCount = inicount; } } // load the auth data, but do not overwrite already stored auth data! if (bSyncAuth) authData.ImportAuthData(syncFolder.GetWinPathString(), password); } else { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Error decrypting, password may be wrong\n"); return false; } } } } } else { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Error opening file %s, Error %u\n", syncPath.GetWinPath(), GetLastError()); auto lasterr = GetLastError(); if ((lasterr != ERROR_FILE_NOT_FOUND) && (lasterr != ERROR_PATH_NOT_FOUND)) return false; } } if (parser.HasKey(L"load")) bCloudIsNewer = true; if (parser.HasKey(L"save")) bCloudIsNewer = false; bool bHaveChanges = false; if (bWithLocals || parser.HasKey(L"local")) { // remove all blocks that are allowed for local exports for (const auto& allow : regBlockLocalArray) { regBlockArray.erase(std::remove(regBlockArray.begin(), regBlockArray.end(), allow), regBlockArray.end()); } } // go through all registry values and update either the registry // or the ini file, depending on which is newer for (const auto& regname : regUseArray) { bool bChanges = HandleRegistryKey(regname, iniFile, bCloudIsNewer); bHaveChanges = bHaveChanges || bChanges; } if (bWithLocals || parser.HasKey(L"local")) { for (const auto& regname : regUseLocalArray) { bool bChanges = HandleRegistryKey(regname, iniFile, bCloudIsNewer); bHaveChanges = bHaveChanges || bChanges; } } if (bCloudIsNewer) { CString regpath = L"Software\\"; CSimpleIni::TNamesDepend keys; iniFile.GetAllKeys(L"registry_dword", keys); for (const auto& k : keys) { CRegDWORD reg(regpath + k); reg = _wtol(iniFile.GetValue(L"registry_dword", k, L"")); } keys.clear(); iniFile.GetAllKeys(L"registry_qword", keys); for (const auto& k : keys) { CRegQWORD reg(regpath + k); reg = _wtoi64(iniFile.GetValue(L"registry_qword", k, L"")); } keys.clear(); iniFile.GetAllKeys(L"registry_string", keys); for (const auto& k : keys) { CRegString reg(regpath + k); reg = CString(iniFile.GetValue(L"registry_string", k, L"")); } } { // sync project monitor settings CString sDataFilePath = CPathUtils::GetAppDataDirectory(); sDataFilePath += L"\\MonitoringData.ini"; CSimpleIni monitorIni; monitorIni.SetMultiLine(true); if (bCloudIsNewer) { CSimpleIni origMonitorIni; origMonitorIni.SetMultiLine(true); origMonitorIni.LoadFile(sDataFilePath); CSimpleIni::TNamesDepend keys; iniFile.GetAllKeys(L"ini_monitor", keys); for (const auto& k : keys) { CString sKey = k; CString sSection = sKey.Left(sKey.Find('.')); sKey = sKey.Mid(sKey.Find('.') + 1); if (sKey.CompareNoCase(L"name") == 0) { // make sure the non-synced values are still used monitorIni.SetValue(sSection, L"lastchecked", origMonitorIni.GetValue(sSection, L"lastchecked", L"0")); monitorIni.SetValue(sSection, L"lastcheckedrobots", origMonitorIni.GetValue(sSection, L"lastcheckedrobots", L"0")); monitorIni.SetValue(sSection, L"lastHEAD", origMonitorIni.GetValue(sSection, L"lastHEAD", L"0")); monitorIni.SetValue(sSection, L"UnreadItems", origMonitorIni.GetValue(sSection, L"UnreadItems", L"0")); monitorIni.SetValue(sSection, L"unreadFirst", origMonitorIni.GetValue(sSection, L"unreadFirst", L"0")); monitorIni.SetValue(sSection, L"WCPathOrUrl", origMonitorIni.GetValue(sSection, L"WCPathOrUrl", L"")); } CString sValue = CString(iniFile.GetValue(L"ini_monitor", k, L"")); if ((sKey.Compare(L"username") == 0) || (sKey.Compare(L"password") == 0)) { sValue = CStringUtils::Encrypt(sValue); } monitorIni.SetValue(sSection, sKey, sValue); } FILE * pFile = NULL; errno_t err = 0; int retrycount = 5; CString sTempfile = CTempFiles::Instance().GetTempFilePathString(); do { err = _tfopen_s(&pFile, sTempfile, L"wb"); if ((err == 0) && pFile) { monitorIni.SaveFile(pFile); err = fclose(pFile); } if (err) { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Error saving %s, retrycount %d\n", (LPCWSTR)sTempfile, retrycount); Sleep(500); } } while (err && retrycount--); if (err == 0) { if (!CopyFile(sTempfile, sDataFilePath, FALSE)) CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Error copying %s to %s, Error %u\n", (LPCWSTR)sTempfile, (LPCWSTR)sDataFilePath, GetLastError()); else { // now send a message to a possible running monitor to force it // to reload the ini file. Otherwise it would overwrite the ini // file without using the synced data! HWND hWnd = FindWindow(NULL, CString(MAKEINTRESOURCE(IDS_MONITOR_DLGTITLE))); if (hWnd) { UINT TSVN_COMMITMONITOR_RELOADINI = RegisterWindowMessage(L"TSVNCommitMonitor_ReloadIni"); PostMessage(hWnd, TSVN_COMMITMONITOR_RELOADINI, 0, 0); } } } } else { CSimpleIni::TNamesDepend mitems; if (PathFileExists(sDataFilePath)) { int retrycount = 5; SI_Error err = SI_OK; do { err = monitorIni.LoadFile(sDataFilePath); if (err == SI_FILE) { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Error loading %s, retrycount %d\n", (LPCWSTR)sDataFilePath, retrycount); Sleep(500); } } while ((err == SI_FILE) && retrycount--); if (err == SI_FILE) { return false; } monitorIni.GetAllSections(mitems); } for (const auto& mitem : mitems) { CString sSection = mitem; CString Name = monitorIni.GetValue(mitem, L"Name", L""); if (!Name.IsEmpty()) { CString newval = monitorIni.GetValue(mitem, L"WCPathOrUrl", L""); iniFile.SetValue(L"ini_monitor", sSection + L".Name", Name); CString oldval = iniFile.GetValue(L"ini_monitor", sSection + L".WCPathOrUrl", L""); bHaveChanges |= ((newval != oldval) && (!oldval.IsEmpty())); // only save monitored working copies if local settings are included, or // if the monitored path is an url. // Don't save paths to working copies for non-local stores if (bWithLocals || newval.IsEmpty() || !PathIsDirectory(newval)) iniFile.SetValue(L"ini_monitor", sSection + L".WCPathOrUrl", newval); newval = monitorIni.GetValue(mitem, L"interval", L"5"); oldval = iniFile.GetValue(L"ini_monitor", sSection + L".interval", L"0"); bHaveChanges |= newval != oldval; iniFile.SetValue(L"ini_monitor", sSection + L".interval", newval); newval = monitorIni.GetValue(mitem, L"minminutesinterval", L"0"); oldval = iniFile.GetValue(L"ini_monitor", sSection + L".minminutesinterval", L"0"); bHaveChanges |= newval != oldval; iniFile.SetValue(L"ini_monitor", sSection + L".minminutesinterval", newval); newval = CStringUtils::Decrypt(monitorIni.GetValue(mitem, L"username", L"")).get(); oldval = iniFile.GetValue(L"ini_monitor", sSection + L".username", L""); bHaveChanges |= newval != oldval; iniFile.SetValue(L"ini_monitor", sSection + L".username", newval); newval = CStringUtils::Decrypt(monitorIni.GetValue(mitem, L"password", L"")).get(); oldval = iniFile.GetValue(L"ini_monitor", sSection + L".password", L""); bHaveChanges |= newval != oldval; iniFile.SetValue(L"ini_monitor", sSection + L".password", newval); newval = monitorIni.GetValue(mitem, L"MsgRegex", L""); oldval = iniFile.GetValue(L"ini_monitor", sSection + L".MsgRegex", L""); bHaveChanges |= newval != oldval; iniFile.SetValue(L"ini_monitor", sSection + L".MsgRegex", newval); newval = monitorIni.GetValue(mitem, L"ignoreauthors", L""); oldval = iniFile.GetValue(L"ini_monitor", sSection + L".ignoreauthors", L""); bHaveChanges |= newval != oldval; iniFile.SetValue(L"ini_monitor", sSection + L".ignoreauthors", newval); newval = monitorIni.GetValue(mitem, L"parentTreePath", L""); oldval = iniFile.GetValue(L"ini_monitor", sSection + L".parentTreePath", L""); bHaveChanges |= newval != oldval; iniFile.SetValue(L"ini_monitor", sSection + L".parentTreePath", newval); newval = monitorIni.GetValue(mitem, L"uuid", L""); oldval = iniFile.GetValue(L"ini_monitor", sSection + L".uuid", L""); bHaveChanges |= newval != oldval; iniFile.SetValue(L"ini_monitor", sSection + L".uuid", newval); newval = monitorIni.GetValue(mitem, L"root", L""); oldval = iniFile.GetValue(L"ini_monitor", sSection + L".root", L""); bHaveChanges |= newval != oldval; iniFile.SetValue(L"ini_monitor", sSection + L".root", newval); ProjectProperties ProjProps; ProjProps.LoadFromIni(monitorIni, sSection); ProjProps.SaveToIni(iniFile, L"ini_monitor", sSection + L".pp_"); } else if (sSection.CompareNoCase(L"global") == 0) { CString newval = monitorIni.GetValue(mitem, L"PlaySound", L"1"); CString oldval = iniFile.GetValue(L"ini_monitor", sSection + L".PlaySound", L"1"); bHaveChanges |= newval != oldval; iniFile.SetValue(L"ini_monitor", sSection + L".PlaySound", newval); newval = monitorIni.GetValue(mitem, L"ShowNotifications", L"1"); oldval = iniFile.GetValue(L"ini_monitor", sSection + L".ShowNotifications", L"1"); bHaveChanges |= newval != oldval; iniFile.SetValue(L"ini_monitor", sSection + L".ShowNotifications", newval); } } } } { // sync TortoiseMerge regex filters CSimpleIni regexIni; regexIni.SetMultiLine(true); CString sDataFilePath = CPathUtils::GetAppDataDirectory(); sDataFilePath += L"\\regexfilters.ini"; if (bCloudIsNewer) { CSimpleIni origRegexIni; if (PathFileExists(sDataFilePath)) { int retrycount = 5; SI_Error err = SI_OK; do { err = origRegexIni.LoadFile(sDataFilePath); if (err == SI_FILE) { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Error loading %s, retrycount %d\n", (LPCWSTR)sDataFilePath, retrycount); Sleep(500); } } while ((err == SI_FILE) && retrycount--); if (err == SI_FILE) { return false; } } CSimpleIni::TNamesDepend keys; iniFile.GetAllKeys(L"ini_tmergeregex", keys); for (const auto& k : keys) { CString sKey = k; CString sSection = sKey.Left(sKey.Find('.')); sKey = sKey.Mid(sKey.Find('.') + 1); CString sValue = CString(iniFile.GetValue(L"ini_tmergeregex", k, L"")); regexIni.SetValue(sSection, sKey, sValue); } FILE * pFile = NULL; errno_t err = 0; int retrycount = 5; CString sTempfile = CTempFiles::Instance().GetTempFilePathString(); do { err = _tfopen_s(&pFile, sTempfile, L"wb"); if ((err == 0) && pFile) { regexIni.SaveFile(pFile); err = fclose(pFile); } if (err) { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Error saving %s, retrycount %d\n", (LPCWSTR)sTempfile, retrycount); Sleep(500); } } while (err && retrycount--); if (err == 0) { if (!CopyFile(sTempfile, sDataFilePath, FALSE)) CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Error copying %s to %s, Error: %u\n", (LPCWSTR)sTempfile, (LPCWSTR)sDataFilePath, GetLastError()); } } else { if (PathFileExists(sDataFilePath)) { int retrycount = 5; SI_Error err = SI_OK; do { err = regexIni.LoadFile(sDataFilePath); if (err == SI_FILE) { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Error loading %s, retrycount %d\n", (LPCWSTR)sDataFilePath, retrycount); Sleep(500); } } while ((err == SI_FILE) && retrycount--); if (err == SI_FILE) { return false; } } CSimpleIni::TNamesDepend mitems; regexIni.GetAllSections(mitems); for (const auto& mitem : mitems) { CString sSection = mitem; CString newval = regexIni.GetValue(mitem, L"regex", L""); CString oldval = iniFile.GetValue(L"ini_tmergeregex", sSection + L".regex", L""); bHaveChanges |= newval != oldval; iniFile.SetValue(L"ini_tmergeregex", sSection + L".regex", newval); newval = regexIni.GetValue(mitem, L"replace", L"5"); oldval = iniFile.GetValue(L"ini_tmergeregex", sSection + L".replace", L"0"); bHaveChanges |= newval != oldval; iniFile.SetValue(L"ini_tmergeregex", sSection + L".replace", newval); } } } if (bHaveChanges) { iniFile.SetValue(L"sync", L"version", TSVN_SYNC_VERSION_STR); DWORD count = regCount; ++count; regCount = count; CString tmp; tmp.Format(L"%lu", count); iniFile.SetValue(L"sync", L"synccounter", tmp); // save the ini file std::string iniData; iniFile.SaveString(iniData); iniData = "***" + iniData; // encrypt the string CString password; if (parser.HasKey(L"askforpath")) { CPasswordDlg passDlg(CWnd::FromHandle(GetExplorerHWND())); passDlg.m_bForSave = true; if (passDlg.DoModal() != IDOK) return false; password = passDlg.m_sPW1; } else { CRegString regPW(L"Software\\TortoiseSVN\\SyncPW"); auto passwordbuf = CStringUtils::Decrypt(CString(regPW)); if (passwordbuf.get()) { password = passwordbuf.get(); } } std::string passworda = CUnicodeUtils::StdGetUTF8((LPCWSTR)password); std::string encrypted = CStringUtils::Encrypt(iniData, passworda); CPathUtils::MakeSureDirectoryPathExists(syncPath.GetContainingDirectory().GetWinPathString()); CString sTempfile = CTempFiles::Instance().GetTempFilePathString(); CAutoFile hFile = CreateFile(sTempfile, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile.IsValid()) { DWORD written = 0; if (WriteFile(hFile, encrypted.c_str(), DWORD(encrypted.size()), &written, NULL)) { if (hFile.CloseHandle()) { if (!CopyFile(sTempfile, syncPath.GetWinPath(), FALSE)) { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Error copying %s to %s, Error: %u\n", (LPCWSTR)sTempfile, syncPath.GetWinPath(), GetLastError()); } else bRet = true; } else CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Error closing file %s, Error: %u\n", (LPCWSTR)sTempfile, GetLastError()); } else CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Error writing to file %s, Error: %u\n", (LPCWSTR)sTempfile, GetLastError()); } else CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Error creating file %s for writing, Error: %u\n", (LPCWSTR)sTempfile, GetLastError()); if (bSyncAuth) { // now save all auth data CPathUtils::MakeSureDirectoryPathExists(syncFolder.GetWinPathString() + L"\\auth"); CPathUtils::MakeSureDirectoryPathExists(syncFolder.GetWinPathString() + L"\\auth\\svn.simple"); CPathUtils::MakeSureDirectoryPathExists(syncFolder.GetWinPathString() + L"\\auth\\svn.ssl.client-passphrase"); CPathUtils::MakeSureDirectoryPathExists(syncFolder.GetWinPathString() + L"\\auth\\svn.ssl.server"); CPathUtils::MakeSureDirectoryPathExists(syncFolder.GetWinPathString() + L"\\auth\\svn.username"); authData.ExportAuthData(syncFolder.GetWinPathString(), password); } } return bRet; }
bool PasteCopyCommand::Execute() { CString sDroppath = parser.GetVal(_T("droptarget")); CTSVNPath dropPath(sDroppath); ProjectProperties props; props.ReadProps(dropPath); if (dropPath.IsAdminDir()) return FALSE; SVN svn; SVNStatus status; unsigned long count = 0; CString sNewName; pathList.RemoveAdminPaths(); CProgressDlg progress; progress.SetTitle(IDS_PROC_COPYING); progress.SetAnimation(IDR_MOVEANI); progress.SetTime(true); progress.ShowModeless(CWnd::FromHandle(hwndExplorer)); for(int nPath = 0; nPath < pathList.GetCount(); nPath++) { const CTSVNPath& sourcePath = pathList[nPath]; CTSVNPath fullDropPath = dropPath; if (sNewName.IsEmpty()) fullDropPath.AppendPathString(sourcePath.GetFileOrDirectoryName()); else fullDropPath.AppendPathString(sNewName); // Check for a drop-on-to-ourselves if (sourcePath.IsEquivalentTo(fullDropPath)) { // Offer a rename progress.Stop(); CRenameDlg dlg; dlg.m_windowtitle.Format(IDS_PROC_NEWNAMECOPY, (LPCTSTR)sourcePath.GetUIFileOrDirectoryName()); if (dlg.DoModal() != IDOK) { return FALSE; } // rebuild the progress dialog progress.EnsureValid(); progress.SetTitle(IDS_PROC_COPYING); progress.SetAnimation(IDR_MOVEANI); progress.SetTime(true); progress.SetProgress(count, pathList.GetCount()); progress.ShowModeless(CWnd::FromHandle(hwndExplorer)); // Rebuild the destination path, with the new name fullDropPath.SetFromUnknown(sDroppath); fullDropPath.AppendPathString(dlg.m_name); } svn_wc_status_kind s = status.GetAllStatus(sourcePath); if ((s == svn_wc_status_none)||(s == svn_wc_status_unversioned)||(s == svn_wc_status_ignored)) { // source file is unversioned: move the file to the target, then add it CopyFile(sourcePath.GetWinPath(), fullDropPath.GetWinPath(), FALSE); if (!svn.Add(CTSVNPathList(fullDropPath), &props, svn_depth_infinity, true, false, true)) { TRACE(_T("%s\n"), (LPCTSTR)svn.GetLastErrorMessage()); CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR); return FALSE; //get out of here } else CShellUpdater::Instance().AddPathForUpdate(fullDropPath); } else { if (!svn.Copy(CTSVNPathList(sourcePath), fullDropPath, SVNRev::REV_WC, SVNRev())) { TRACE(_T("%s\n"), (LPCTSTR)svn.GetLastErrorMessage()); CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR); return FALSE; //get out of here } else CShellUpdater::Instance().AddPathForUpdate(fullDropPath); } count++; if (progress.IsValid()) { progress.FormatPathLine(1, IDS_PROC_COPYINGPROG, sourcePath.GetWinPath()); progress.FormatPathLine(2, IDS_PROC_CPYMVPROG2, fullDropPath.GetWinPath()); progress.SetProgress(count, pathList.GetCount()); } if ((progress.IsValid())&&(progress.HasUserCancelled())) { CMessageBox::Show(hwndExplorer, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_ICONINFORMATION); return false; } } return true; }
bool SVNDiff::DiffWCFile(const CTSVNPath& filePath, bool ignoreprops, svn_wc_status_kind status, /* = svn_wc_status_none */ svn_wc_status_kind text_status /* = svn_wc_status_none */, svn_wc_status_kind prop_status /* = svn_wc_status_none */, svn_wc_status_kind remotetext_status /* = svn_wc_status_none */, svn_wc_status_kind remoteprop_status /* = svn_wc_status_none */) { CTSVNPath basePath; CTSVNPath remotePath; SVNRev remoteRev; svn_revnum_t baseRev = 0; // first diff the remote properties against the wc props // TODO: should we attempt to do a three way diff with the properties too // if they're modified locally and remotely? if (!ignoreprops && (remoteprop_status > svn_wc_status_normal)) { DiffProps(filePath, SVNRev::REV_HEAD, SVNRev::REV_WC, baseRev); } if (!ignoreprops && (prop_status > svn_wc_status_normal)&&(filePath.IsDirectory())) { DiffProps(filePath, SVNRev::REV_WC, SVNRev::REV_BASE, baseRev); } if (filePath.IsDirectory()) return true; if ((status > svn_wc_status_normal) || (text_status > svn_wc_status_normal)) { basePath = SVN::GetPristinePath(filePath); if (baseRev == 0) { SVNStatus stat; CTSVNPath dummy; svn_client_status_t * s = stat.GetFirstFileStatus(filePath, dummy); if (s) baseRev = s->revision >= 0 ? s->revision : s->changed_rev; } // If necessary, convert the line-endings on the file before diffing if ((DWORD)CRegDWORD(L"Software\\TortoiseSVN\\ConvertBase", TRUE)) { CTSVNPath temporaryFile = CTempFiles::Instance().GetTempFilePath(m_bRemoveTempFiles, filePath, SVNRev::REV_BASE); if (!m_pSVN->Export(filePath, temporaryFile, SVNRev(SVNRev::REV_BASE), SVNRev(SVNRev::REV_BASE))) { temporaryFile.Reset(); } else { basePath = temporaryFile; SetFileAttributes(basePath.GetWinPath(), FILE_ATTRIBUTE_READONLY); } } } if (remotetext_status > svn_wc_status_normal) { remotePath = CTempFiles::Instance().GetTempFilePath(false, filePath, SVNRev::REV_HEAD); CProgressDlg progDlg; progDlg.SetTitle(IDS_APPNAME); progDlg.SetTime(false); m_pSVN->SetAndClearProgressInfo(&progDlg, true); // activate progress bar progDlg.ShowModeless(GetHWND()); progDlg.FormatPathLine(1, IDS_PROGRESSGETFILE, (LPCTSTR)filePath.GetUIFileOrDirectoryName()); remoteRev = SVNRev::REV_HEAD; if (!m_pSVN->Export(filePath, remotePath, remoteRev, remoteRev)) { progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); m_pSVN->ShowErrorDialog(GetHWND()); return false; } progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); SetFileAttributes(remotePath.GetWinPath(), FILE_ATTRIBUTE_READONLY); } CString name = filePath.GetUIFileOrDirectoryName(); CString n1, n2, n3; n1.Format(IDS_DIFF_WCNAME, (LPCTSTR)name); if (baseRev) n2.FormatMessage(IDS_DIFF_BASENAMEREV, (LPCTSTR)name, baseRev); else n2.Format(IDS_DIFF_BASENAME, (LPCTSTR)name); n3.Format(IDS_DIFF_REMOTENAME, (LPCTSTR)name); if ((text_status <= svn_wc_status_normal)&&(prop_status <= svn_wc_status_normal)&&(status <= svn_wc_status_normal)) { // Hasn't changed locally - diff remote against WC return CAppUtils::StartExtDiff( filePath, remotePath, n1, n3, filePath, filePath, SVNRev::REV_WC, remoteRev, remoteRev, CAppUtils::DiffFlags().AlternativeTool(m_bAlternativeTool), m_JumpLine, filePath.GetFileOrDirectoryName(), L""); } else if (remotePath.IsEmpty()) { return DiffFileAgainstBase(filePath, baseRev, ignoreprops, status, text_status, prop_status); } else { // Three-way diff CAppUtils::MergeFlags flags; flags.bAlternativeTool = m_bAlternativeTool; flags.bReadOnly = true; return !!CAppUtils::StartExtMerge(flags, basePath, remotePath, filePath, CTSVNPath(), false, n2, n3, n1, CString(), filePath.GetFileOrDirectoryName()); } }
bool SVNDiff::DiffProps(const CTSVNPath& filePath, const SVNRev& rev1, const SVNRev& rev2, svn_revnum_t &baseRev) const { bool retvalue = false; // diff the properties SVNProperties propswc(filePath, rev1, false, false); SVNProperties propsbase(filePath, rev2, false, false); #define MAX_PATH_LENGTH 80 WCHAR pathbuf1[MAX_PATH] = {0}; if (filePath.GetWinPathString().GetLength() >= MAX_PATH) { std::wstring str = filePath.GetWinPath(); std::wregex rx(L"^(\\w+:|(?:\\\\|/+))((?:\\\\|/+)[^\\\\/]+(?:\\\\|/)[^\\\\/]+(?:\\\\|/)).*((?:\\\\|/)[^\\\\/]+(?:\\\\|/)[^\\\\/]+)$"); std::wstring replacement = L"$1$2...$3"; std::wstring str2 = std::regex_replace(str, rx, replacement); if (str2.size() >= MAX_PATH) str2 = str2.substr(0, MAX_PATH-2); PathCompactPathEx(pathbuf1, str2.c_str(), MAX_PATH_LENGTH, 0); } else PathCompactPathEx(pathbuf1, filePath.GetWinPath(), MAX_PATH_LENGTH, 0); if ((baseRev == 0) && (!filePath.IsUrl()) && (rev1.IsBase() || rev2.IsBase())) { SVNStatus stat; CTSVNPath dummy; svn_client_status_t * s = stat.GetFirstFileStatus(filePath, dummy); if (s) baseRev = s->revision; } // check for properties that got removed for (int baseindex = 0; baseindex < propsbase.GetCount(); ++baseindex) { std::string basename = propsbase.GetItemName(baseindex); tstring basenameU = CUnicodeUtils::StdGetUnicode(basename); tstring basevalue = (LPCTSTR)CUnicodeUtils::GetUnicode(propsbase.GetItemValue(baseindex).c_str()); bool bFound = false; for (int wcindex = 0; wcindex < propswc.GetCount(); ++wcindex) { if (basename.compare (propswc.GetItemName(wcindex))==0) { bFound = true; break; } } if (!bFound) { // write the old property value to temporary file CTSVNPath wcpropfile = CTempFiles::Instance().GetTempFilePath(false); CTSVNPath basepropfile = CTempFiles::Instance().GetTempFilePath(false); FILE * pFile; _tfopen_s(&pFile, wcpropfile.GetWinPath(), L"wb"); if (pFile) { fclose(pFile); FILE * pFile2; _tfopen_s(&pFile2, basepropfile.GetWinPath(), L"wb"); if (pFile2) { fputs(CUnicodeUtils::StdGetUTF8(basevalue).c_str(), pFile2); fclose(pFile2); } else return false; } else return false; SetFileAttributes(wcpropfile.GetWinPath(), FILE_ATTRIBUTE_READONLY); SetFileAttributes(basepropfile.GetWinPath(), FILE_ATTRIBUTE_READONLY); CString n1, n2; bool bSwitch = false; if (rev1.IsWorking()) n1.Format(IDS_DIFF_PROP_WCNAME, basenameU.c_str()); if (rev1.IsBase()) { if (baseRev) n1.FormatMessage(IDS_DIFF_PROP_BASENAMEREV, basenameU.c_str(), baseRev); else n1.Format(IDS_DIFF_PROP_BASENAME, basenameU.c_str()); } if (rev1.IsHead()) n1.Format(IDS_DIFF_PROP_REMOTENAME, basenameU.c_str()); if (n1.IsEmpty()) { CString temp; temp.Format(IDS_DIFF_REVISIONPATCHED, (LONG)rev1); n1 = basenameU.c_str(); n1 += L" " + temp; bSwitch = true; } else { n1 = CString(pathbuf1) + L" - " + n1; } if (rev2.IsWorking()) n2.Format(IDS_DIFF_PROP_WCNAME, basenameU.c_str()); if (rev2.IsBase()) { if (baseRev) n2.FormatMessage(IDS_DIFF_PROP_BASENAMEREV, basenameU.c_str(), baseRev); else n2.Format(IDS_DIFF_PROP_BASENAME, basenameU.c_str()); } if (rev2.IsHead()) n2.Format(IDS_DIFF_PROP_REMOTENAME, basenameU.c_str()); if (n2.IsEmpty()) { CString temp; temp.Format(IDS_DIFF_REVISIONPATCHED, (LONG)rev2); n2 = basenameU.c_str(); n2 += L" " + temp; bSwitch = true; } else { n2 = CString(pathbuf1) + L" - " + n2; } if (bSwitch) { retvalue = !!CAppUtils::StartExtDiffProps(wcpropfile, basepropfile, n1, n2, TRUE, TRUE); } else { retvalue = !!CAppUtils::StartExtDiffProps(basepropfile, wcpropfile, n2, n1, TRUE, TRUE); } } } for (int wcindex = 0; wcindex < propswc.GetCount(); ++wcindex) { std::string wcname = propswc.GetItemName(wcindex); tstring wcnameU = CUnicodeUtils::StdGetUnicode(wcname); tstring wcvalue = (LPCTSTR)CUnicodeUtils::GetUnicode(propswc.GetItemValue(wcindex).c_str()); tstring basevalue; bool bDiffRequired = true; for (int baseindex = 0; baseindex < propsbase.GetCount(); ++baseindex) { if (propsbase.GetItemName(baseindex).compare(wcname)==0) { basevalue = CUnicodeUtils::GetUnicode(propsbase.GetItemValue(baseindex).c_str()); if (basevalue.compare(wcvalue)==0) { // name and value are identical bDiffRequired = false; break; } } } if (bDiffRequired) { // write both property values to temporary files CTSVNPath wcpropfile = CTempFiles::Instance().GetTempFilePath(false); CTSVNPath basepropfile = CTempFiles::Instance().GetTempFilePath(false); FILE * pFile; _tfopen_s(&pFile, wcpropfile.GetWinPath(), L"wb"); if (pFile) { fputs(CUnicodeUtils::StdGetUTF8(wcvalue).c_str(), pFile); fclose(pFile); FILE * pFile2; _tfopen_s(&pFile2, basepropfile.GetWinPath(), L"wb"); if (pFile2) { fputs(CUnicodeUtils::StdGetUTF8(basevalue).c_str(), pFile2); fclose(pFile2); } else return false; } else return false; SetFileAttributes(wcpropfile.GetWinPath(), FILE_ATTRIBUTE_READONLY); SetFileAttributes(basepropfile.GetWinPath(), FILE_ATTRIBUTE_READONLY); CString n1, n2; if (rev1.IsWorking()) n1.Format(IDS_DIFF_WCNAME, wcnameU.c_str()); if (rev1.IsBase()) n1.Format(IDS_DIFF_BASENAME, wcnameU.c_str()); if (rev1.IsHead()) n1.Format(IDS_DIFF_REMOTENAME, wcnameU.c_str()); if (n1.IsEmpty()) n1.FormatMessage(IDS_DIFF_PROP_REVISIONNAME, wcnameU.c_str(), (LPCTSTR)rev1.ToString()); else n1 = CString(pathbuf1) + L" - " + n1; if (rev2.IsWorking()) n2.Format(IDS_DIFF_WCNAME, wcnameU.c_str()); if (rev2.IsBase()) n2.Format(IDS_DIFF_BASENAME, wcnameU.c_str()); if (rev2.IsHead()) n2.Format(IDS_DIFF_REMOTENAME, wcnameU.c_str()); if (n2.IsEmpty()) n2.FormatMessage(IDS_DIFF_PROP_REVISIONNAME, wcnameU.c_str(), (LPCTSTR)rev2.ToString()); else n2 = CString(pathbuf1) + L" - " + n2; retvalue = !!CAppUtils::StartExtDiffProps(basepropfile, wcpropfile, n2, n1, TRUE, TRUE); } } return retvalue; }
bool SVNDiff::DiffFileAgainstBase( const CTSVNPath& filePath, svn_revnum_t & baseRev, bool ignoreprops, svn_wc_status_kind status /*= svn_wc_status_none*/, svn_wc_status_kind text_status /*= svn_wc_status_none*/, svn_wc_status_kind prop_status /*= svn_wc_status_none*/ ) { bool retvalue = false; bool fileexternal = false; if ((text_status == svn_wc_status_none)||(prop_status == svn_wc_status_none)) { SVNStatus stat; stat.GetStatus(filePath); if (stat.status == NULL) return false; text_status = stat.status->text_status; prop_status = stat.status->prop_status; fileexternal = stat.status->file_external != 0; } if (!ignoreprops && (prop_status > svn_wc_status_normal)) { DiffProps(filePath, SVNRev::REV_WC, SVNRev::REV_BASE, baseRev); } if (filePath.IsDirectory()) return true; if ((status >= svn_wc_status_normal) || (text_status >= svn_wc_status_normal)) { CTSVNPath basePath(SVN::GetPristinePath(filePath)); if (baseRev == 0) { SVNInfo info; const SVNInfoData * infodata = info.GetFirstFileInfo(filePath, SVNRev(), SVNRev()); if (infodata) { if (infodata->copyfromurl && infodata->copyfromurl[0]) baseRev = infodata->copyfromrev; else baseRev = infodata->lastchangedrev; } } // If necessary, convert the line-endings on the file before diffing // note: file externals can not be exported if (((DWORD)CRegDWORD(L"Software\\TortoiseSVN\\ConvertBase", TRUE)) && (!fileexternal)) { CTSVNPath temporaryFile = CTempFiles::Instance().GetTempFilePath(m_bRemoveTempFiles, filePath, SVNRev::REV_BASE); if (!m_pSVN->Export(filePath, temporaryFile, SVNRev(SVNRev::REV_BASE), SVNRev(SVNRev::REV_BASE))) { temporaryFile.Reset(); } else { basePath = temporaryFile; SetFileAttributes(basePath.GetWinPath(), FILE_ATTRIBUTE_READONLY); } } // for added/deleted files, we don't have a BASE file. // create an empty temp file to be used. if (!basePath.Exists()) { basePath = CTempFiles::Instance().GetTempFilePath(m_bRemoveTempFiles, filePath, SVNRev::REV_BASE); SetFileAttributes(basePath.GetWinPath(), FILE_ATTRIBUTE_READONLY); } CString name = filePath.GetFilename(); CTSVNPath wcFilePath = filePath; if (!wcFilePath.Exists()) { wcFilePath = CTempFiles::Instance().GetTempFilePath(m_bRemoveTempFiles, filePath, SVNRev::REV_BASE); SetFileAttributes(wcFilePath.GetWinPath(), FILE_ATTRIBUTE_READONLY); } CString n1, n2; n1.Format(IDS_DIFF_WCNAME, (LPCTSTR)name); if (baseRev) n2.FormatMessage(IDS_DIFF_BASENAMEREV, (LPCTSTR)name, baseRev); else n2.Format(IDS_DIFF_BASENAME, (LPCTSTR)name); retvalue = CAppUtils::StartExtDiff( basePath, wcFilePath, n2, n1, filePath, filePath, SVNRev::REV_BASE, SVNRev::REV_WC, SVNRev::REV_BASE, CAppUtils::DiffFlags().Wait().AlternativeTool(m_bAlternativeTool), m_JumpLine, name, L""); } return retvalue; }
bool SVNDiff::ShowCompare( const CTSVNPath& url1, const SVNRev& rev1, const CTSVNPath& url2, const SVNRev& rev2, SVNRev peg, bool ignoreprops, const CString& options, bool ignoreancestry /*= false*/, bool blame /*= false*/, svn_node_kind_t nodekind /*= svn_node_unknown*/ ) { CTSVNPath tempfile; CString mimetype; CProgressDlg progDlg; progDlg.SetTitle(IDS_APPNAME); progDlg.SetTime(false); m_pSVN->SetAndClearProgressInfo(&progDlg); CAppUtils::DiffFlags diffFlags; diffFlags.ReadOnly().AlternativeTool(m_bAlternativeTool); if ((m_pSVN->PathIsURL(url1))||(!rev1.IsWorking())||(!url1.IsEquivalentTo(url2))) { // no working copy path! progDlg.ShowModeless(GetHWND()); tempfile = CTempFiles::Instance().GetTempFilePath(false, url1); // first find out if the url points to a file or dir CString sRepoRoot; if ((nodekind != svn_node_dir)&&(nodekind != svn_node_file)) { progDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROGRESS_INFO))); SVNInfo info; const SVNInfoData * data = info.GetFirstFileInfo(url1, (peg.IsValid() ? peg : m_headPeg), rev1, svn_depth_empty); if (data == NULL) { data = info.GetFirstFileInfo(url1, (peg.IsValid() ? peg : rev1), rev1, svn_depth_empty); if (data == NULL) { data = info.GetFirstFileInfo(url1, (peg.IsValid() ? peg : rev2), rev1, svn_depth_empty); if (data == NULL) { progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); info.ShowErrorDialog(GetHWND()); return false; } else { sRepoRoot = data->reposRoot; nodekind = data->kind; peg = peg.IsValid() ? peg : rev2; } } else { sRepoRoot = data->reposRoot; nodekind = data->kind; peg = peg.IsValid() ? peg : rev1; } } else { sRepoRoot = data->reposRoot; nodekind = data->kind; peg = peg.IsValid() ? peg : m_headPeg; } } else { sRepoRoot = m_pSVN->GetRepositoryRoot(url1); peg = peg.IsValid() ? peg : m_headPeg; } if (nodekind == svn_node_dir) { if (rev1.IsWorking()) { if (UnifiedDiff(tempfile, url1, rev1, url2, rev2, (peg.IsValid() ? peg : SVNRev::REV_WC), options)) { CString sWC; sWC.LoadString(IDS_DIFF_WORKINGCOPY); progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); return !!CAppUtils::StartExtPatch(tempfile, url1.GetDirectory(), sWC, url2.GetSVNPathString(), TRUE); } } else { progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); CFileDiffDlg fdlg; fdlg.DoBlame(blame); if (url1.IsEquivalentTo(url2)) { fdlg.SetDiff(url1, (peg.IsValid() ? peg : m_headPeg), rev1, rev2, svn_depth_infinity, ignoreancestry); fdlg.DoModal(); } else { fdlg.SetDiff(url1, rev1, url2, rev2, svn_depth_infinity, ignoreancestry); fdlg.DoModal(); } } } else { if (url1.IsEquivalentTo(url2) && !ignoreprops) { svn_revnum_t baseRev = 0; DiffProps(url1, rev2, rev1, baseRev); } // diffing two revs of a file, so export two files CTSVNPath tempfile1 = CTempFiles::Instance().GetTempFilePath(m_bRemoveTempFiles, blame ? CTSVNPath() : url1, rev1); CTSVNPath tempfile2 = CTempFiles::Instance().GetTempFilePath(m_bRemoveTempFiles, blame ? CTSVNPath() : url2, rev2); m_pSVN->SetAndClearProgressInfo(&progDlg, true); // activate progress bar progDlg.FormatPathLine(1, IDS_PROGRESSGETFILEREVISION, (LPCTSTR)url1.GetUIFileOrDirectoryName(), (LPCTSTR)rev1.ToString()); CAppUtils::GetMimeType(url1, mimetype, rev1); CBlame blamer; blamer.SetAndClearProgressInfo(&progDlg, true); if (blame) { if (!blamer.BlameToFile(url1, 1, rev1, peg.IsValid() ? peg : rev1, tempfile1, options, TRUE, TRUE)) { if ((peg.IsValid())&&(blamer.GetSVNError()->apr_err != SVN_ERR_CLIENT_IS_BINARY_FILE)) { if (!blamer.BlameToFile(url1, 1, rev1, rev1, tempfile1, options, TRUE, TRUE)) { progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); blamer.ShowErrorDialog(GetHWND()); return false; } } else { if (blamer.GetSVNError()->apr_err != SVN_ERR_CLIENT_IS_BINARY_FILE) { progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); } blamer.ShowErrorDialog(GetHWND()); if (blamer.GetSVNError()->apr_err == SVN_ERR_CLIENT_IS_BINARY_FILE) blame = false; else return false; } } } if (!blame) { bool tryWorking = (!m_pSVN->PathIsURL(url1) && rev1.IsWorking() && PathFileExists(url1.GetWinPath())); if (!m_pSVN->Export(url1, tempfile1, peg.IsValid() && !tryWorking ? peg : rev1, rev1)) { if (peg.IsValid()) { if (!m_pSVN->Export(url1, tempfile1, rev1, rev1)) { progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); m_pSVN->ShowErrorDialog(GetHWND()); return false; } } else { progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); m_pSVN->ShowErrorDialog(GetHWND()); return false; } } } SetFileAttributes(tempfile1.GetWinPath(), FILE_ATTRIBUTE_READONLY); progDlg.FormatPathLine(1, IDS_PROGRESSGETFILEREVISION, (LPCTSTR)url2.GetUIFileOrDirectoryName(), (LPCTSTR)rev2.ToString()); progDlg.SetProgress(50,100); if (blame) { if (!blamer.BlameToFile(url2, 1, rev2, peg.IsValid() ? peg : rev2, tempfile2, options, TRUE, TRUE)) { if (peg.IsValid()) { if (!blamer.BlameToFile(url2, 1, rev2, rev2, tempfile2, options, TRUE, TRUE)) { progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); m_pSVN->ShowErrorDialog(GetHWND()); return false; } } else { progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); m_pSVN->ShowErrorDialog(GetHWND()); return false; } } } else { if (!m_pSVN->Export(url2, tempfile2, peg.IsValid() ? peg : rev2, rev2)) { if (peg.IsValid()) { if (!m_pSVN->Export(url2, tempfile2, rev2, rev2)) { progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); m_pSVN->ShowErrorDialog(GetHWND()); return false; } } else { progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); m_pSVN->ShowErrorDialog(GetHWND()); return false; } } } SetFileAttributes(tempfile2.GetWinPath(), FILE_ATTRIBUTE_READONLY); progDlg.SetProgress(100,100); progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); CString revname1, revname2; if (url1.IsEquivalentTo(url2)) { revname1.Format(L"%s Revision %s", (LPCTSTR)url1.GetUIFileOrDirectoryName(), (LPCTSTR)rev1.ToString()); revname2.Format(L"%s Revision %s", (LPCTSTR)url2.GetUIFileOrDirectoryName(), (LPCTSTR)rev2.ToString()); } else { if (sRepoRoot.IsEmpty()) { revname1.Format(L"%s Revision %s", (LPCTSTR)url1.GetSVNPathString(), (LPCTSTR)rev1.ToString()); revname2.Format(L"%s Revision %s", (LPCTSTR)url2.GetSVNPathString(), (LPCTSTR)rev2.ToString()); } else { if (url1.IsUrl()) revname1.Format(L"%s Revision %s", (LPCTSTR)url1.GetSVNPathString().Mid(sRepoRoot.GetLength()), (LPCTSTR)rev1.ToString()); else revname1.Format(L"%s Revision %s", (LPCTSTR)url1.GetSVNPathString(), (LPCTSTR)rev1.ToString()); if (url2.IsUrl() && (url2.GetSVNPathString().Left(sRepoRoot.GetLength()).Compare(sRepoRoot) == 0)) revname2.Format(L"%s Revision %s", (LPCTSTR)url2.GetSVNPathString().Mid(sRepoRoot.GetLength()), (LPCTSTR)rev2.ToString()); else revname2.Format(L"%s Revision %s", (LPCTSTR)url2.GetSVNPathString(), (LPCTSTR)rev2.ToString()); } } return CAppUtils::StartExtDiff(tempfile1, tempfile2, revname1, revname2, url1, url2, rev1, rev2, peg, diffFlags.Blame(blame), m_JumpLine, L"", mimetype); } } else { // compare with working copy if (PathIsDirectory(url1.GetWinPath())) { if (UnifiedDiff(tempfile, url1, rev1, url1, rev2, (peg.IsValid() ? peg : SVNRev::REV_WC), options)) { CString sWC, sRev; sWC.LoadString(IDS_DIFF_WORKINGCOPY); sRev.Format(IDS_DIFF_REVISIONPATCHED, (LONG)rev2); progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); return !!CAppUtils::StartExtPatch(tempfile, url1.GetDirectory(), sWC, sRev, TRUE); } } else { ASSERT(rev1.IsWorking()); if (url1.IsEquivalentTo(url2) && !ignoreprops) { svn_revnum_t baseRev = 0; DiffProps(url1, rev1, rev2, baseRev); } m_pSVN->SetAndClearProgressInfo(&progDlg, true); // activate progress bar progDlg.ShowModeless(GetHWND()); progDlg.FormatPathLine(1, IDS_PROGRESSGETFILEREVISION, (LPCTSTR)url1.GetUIFileOrDirectoryName(), (LPCTSTR)rev2.ToString()); tempfile = CTempFiles::Instance().GetTempFilePath(m_bRemoveTempFiles, url1, rev2); if (blame) { CBlame blamer; if (!blamer.BlameToFile(url1, 1, rev2, (peg.IsValid() ? peg : SVNRev::REV_WC), tempfile, options, TRUE, TRUE)) { if (peg.IsValid()) { if (!blamer.BlameToFile(url1, 1, rev2, SVNRev::REV_WC, tempfile, options, TRUE, TRUE)) { progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); m_pSVN->ShowErrorDialog(GetHWND()); return false; } } else { progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); m_pSVN->ShowErrorDialog(GetHWND()); return false; } } progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY); CTSVNPath tempfile2 = CTempFiles::Instance().GetTempFilePath(false, url1); if (!blamer.BlameToFile(url1, 1, SVNRev::REV_WC, SVNRev::REV_WC, tempfile2, options, TRUE, TRUE)) { progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); m_pSVN->ShowErrorDialog(GetHWND()); return false; } CString revname, wcname; revname.Format(L"%s Revision %ld", (LPCTSTR)url1.GetFilename(), (LONG)rev2); wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)url1.GetFilename()); m_pSVN->SetAndClearProgressInfo((HWND)NULL); return CAppUtils::StartExtDiff(tempfile, tempfile2, revname, wcname, url1, url2, rev1, rev2, peg, diffFlags, m_JumpLine, url1.GetFileOrDirectoryName(), L""); } else { if (!m_pSVN->Export(url1, tempfile, (peg.IsValid() ? peg : SVNRev::REV_WC), rev2)) { if (peg.IsValid()) { if (!m_pSVN->Export(url1, tempfile, SVNRev::REV_WC, rev2)) { progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); m_pSVN->ShowErrorDialog(GetHWND()); return false; } } else { progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); m_pSVN->ShowErrorDialog(GetHWND()); return false; } } progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); SetFileAttributes(tempfile.GetWinPath(), FILE_ATTRIBUTE_READONLY); CString revname, wcname; revname.Format(L"%s Revision %s", (LPCTSTR)url1.GetFilename(), (LPCTSTR)rev2.ToString()); wcname.Format(IDS_DIFF_WCNAME, (LPCTSTR)url1.GetFilename()); return CAppUtils::StartExtDiff(tempfile, url1, revname, wcname, url1, url1, rev2, rev1, peg, diffFlags, m_JumpLine, url1.GetFileOrDirectoryName(), L""); } } } m_pSVN->SetAndClearProgressInfo((HWND)NULL); return false; }
void CCachedDirectory::AddEntry(const CTSVNPath& path, const svn_client_status_t* pSVNStatus, bool needsLock, bool forceNormal) { svn_wc_status_kind nodestatus = forceNormal ? svn_wc_status_normal : (pSVNStatus ? pSVNStatus->node_status : svn_wc_status_none); if(path.IsDirectory()) { // no lock here: // AutoLocker lock(m_critSec); // because GetDirectoryCacheEntry() can try to obtain a write lock CCachedDirectory * childDir = CSVNStatusCache::Instance().GetDirectoryCacheEntry(path); if (childDir) { if ((childDir->GetCurrentFullStatus() != svn_wc_status_ignored)||(pSVNStatus==NULL)||(nodestatus != svn_wc_status_unversioned)) childDir->m_ownStatus.SetStatus(pSVNStatus, needsLock, forceNormal); childDir->m_ownStatus.SetKind(svn_node_dir); } } else { AutoLocker lock(m_critSec); CStringA cachekey = GetCacheKey(path); CacheEntryMap::iterator entry_it = m_entryCache.lower_bound(cachekey); if (entry_it != m_entryCache.end() && entry_it->first == cachekey) { if (pSVNStatus) { if (entry_it->second.GetEffectiveStatus() > svn_wc_status_none && entry_it->second.GetEffectiveStatus() != nodestatus) { CSVNStatusCache::Instance().UpdateShell(path); CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) _T(": shell update for %s\n"), path.GetWinPath()); } } } else { entry_it = m_entryCache.insert(entry_it, std::make_pair(cachekey, CStatusCacheEntry())); } entry_it->second = CStatusCacheEntry(pSVNStatus, needsLock, path.GetLastWriteTime(), forceNormal); } }
bool CDirectoryWatcher::AddPath(const CTSVNPath& path, bool bCloseInfoMap) { if (!CSVNStatusCache::Instance().IsPathAllowed(path)) return false; if ((!blockedPath.IsEmpty())&&(blockedPath.IsAncestorOf(path))) { if (GetTickCount64() < blockTickCount) { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Path %s prevented from being watched\n", path.GetWinPath()); return false; } } // ignore the recycle bin PTSTR pFound = StrStrI(path.GetWinPath(), L":\\RECYCLER"); if (pFound != NULL) { if ((*(pFound + 10) == '\0') || (*(pFound + 10) == '\\')) return false; } pFound = StrStrI(path.GetWinPath(), L":\\$Recycle.Bin"); if (pFound != NULL) { if ((*(pFound + 14) == '\0') || (*(pFound + 14) == '\\')) return false; } AutoLocker lock(m_critSec); for (int i=0; i<watchedPaths.GetCount(); ++i) { if (watchedPaths[i].IsAncestorOf(path)) return false; // already watched (recursively) } // now check if with the new path we might have a new root CTSVNPath newroot; for (int i=0; i<watchedPaths.GetCount(); ++i) { const CString& watched = watchedPaths[i].GetWinPathString(); const CString& sPath = path.GetWinPathString(); int minlen = min(sPath.GetLength(), watched.GetLength()); int len = 0; for (len = 0; len < minlen; ++len) { if (watched.GetAt(len) != sPath.GetAt(len)) { if ((len > 1)&&(len < minlen)) { if (sPath.GetAt(len)=='\\') { newroot = CTSVNPath(sPath.Left(len)); } else if (watched.GetAt(len)=='\\') { newroot = CTSVNPath(watched.Left(len)); } } break; } } if (len == minlen) { if (sPath.GetLength() == minlen) { if (watched.GetLength() > minlen) { if (watched.GetAt(len)=='\\') { newroot = path; } else if (sPath.GetLength() == 3 && sPath[1] == ':') { newroot = path; } } } else { if (sPath.GetLength() > minlen) { if (sPath.GetAt(len)=='\\') { newroot = CTSVNPath(watched); } else if (watched.GetLength() == 3 && watched[1] == ':') { newroot = CTSVNPath(watched); } } } } } if (!newroot.IsEmpty() && SVNHelper::IsVersioned(newroot, false)) { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": AddPath for %s\n", newroot.GetWinPath()); watchedPaths.AddPath(newroot); watchedPaths.RemoveChildren(); if (bCloseInfoMap) ClearInfoMap(); return true; } if (!SVNHelper::IsVersioned(path, false)) { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": Path %s prevented from being watched: not versioned\n", path.GetWinPath()); return false; } CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": AddPath for %s\n", path.GetWinPath()); watchedPaths.AddPath(path); if (bCloseInfoMap) ClearInfoMap(); return true; }
bool PasteMoveCommand::Execute() { CString sDroppath = parser.GetVal(L"droptarget"); CTSVNPath dropPath(sDroppath); ProjectProperties props; props.ReadProps(dropPath); if (dropPath.IsAdminDir()) return FALSE; SVN svn; SVNStatus status; unsigned long count = 0; pathList.RemoveAdminPaths(); CString sNewName; CProgressDlg progress; progress.SetTitle(IDS_PROC_MOVING); progress.SetTime(true); progress.ShowModeless(CWnd::FromHandle(GetExplorerHWND())); for(int nPath = 0; nPath < pathList.GetCount(); nPath++) { CTSVNPath destPath; if (sNewName.IsEmpty()) destPath = CTSVNPath(sDroppath+L"\\"+pathList[nPath].GetFileOrDirectoryName()); else destPath = CTSVNPath(sDroppath+L"\\"+sNewName); if (destPath.Exists()) { CString name = pathList[nPath].GetFileOrDirectoryName(); if (!sNewName.IsEmpty()) name = sNewName; progress.Stop(); CRenameDlg dlg; dlg.SetFileSystemAutoComplete(); dlg.m_name = name; dlg.SetInputValidator(this); m_renPath = pathList[nPath]; dlg.m_windowtitle.Format(IDS_PROC_NEWNAMEMOVE, (LPCTSTR)name); if (dlg.DoModal() != IDOK) { return FALSE; } destPath.SetFromWin(sDroppath+L"\\"+dlg.m_name); } svn_wc_status_kind s = status.GetAllStatus(pathList[nPath]); if ((s == svn_wc_status_none)||(s == svn_wc_status_unversioned)||(s == svn_wc_status_ignored)) { // source file is unversioned: move the file to the target, then add it MoveFile(pathList[nPath].GetWinPath(), destPath.GetWinPath()); if (!svn.Add(CTSVNPathList(destPath), &props, svn_depth_infinity, true, true, false, true)) { svn.ShowErrorDialog(GetExplorerHWND()); return FALSE; //get out of here } CShellUpdater::Instance().AddPathForUpdate(destPath); } else { if (!svn.Move(CTSVNPathList(pathList[nPath]), destPath)) { svn.ShowErrorDialog(GetExplorerHWND()); return FALSE; //get out of here } else CShellUpdater::Instance().AddPathForUpdate(destPath); } count++; if (progress.IsValid()) { progress.FormatPathLine(1, IDS_PROC_MOVINGPROG, pathList[nPath].GetWinPath()); progress.FormatPathLine(2, IDS_PROC_CPYMVPROG2, destPath.GetWinPath()); progress.SetProgress(count, pathList.GetCount()); } if ((progress.IsValid())&&(progress.HasUserCancelled())) { TaskDialog(GetExplorerHWND(), AfxGetResourceHandle(), MAKEINTRESOURCE(IDS_APPNAME), MAKEINTRESOURCE(IDS_SVN_USERCANCELLED), NULL, TDCBF_OK_BUTTON, TD_INFORMATION_ICON, NULL); return FALSE; } } return true; }
bool DropMoveCommand::Execute() { CString droppath = parser.GetVal(_T("droptarget")); if (CTSVNPath(droppath).IsAdminDir()) return FALSE; SVN svn; unsigned long count = 0; pathList.RemoveAdminPaths(); CString sNewName; if ((parser.HasKey(_T("rename")))&&(pathList.GetCount()==1)) { // ask for a new name of the source item CRenameDlg renDlg; renDlg.SetInputValidator(this); renDlg.m_windowtitle.LoadString(IDS_PROC_MOVERENAME); renDlg.m_name = pathList[0].GetFileOrDirectoryName(); if (renDlg.DoModal() != IDOK) { return FALSE; } sNewName = renDlg.m_name; } CProgressDlg progress; if (progress.IsValid()) { progress.SetTitle(IDS_PROC_MOVING); progress.SetAnimation(IDR_MOVEANI); progress.SetTime(true); progress.ShowModeless(CWnd::FromHandle(GetExplorerHWND())); } UINT msgRet = IDNO; for(int nPath = 0; nPath < pathList.GetCount(); nPath++) { CTSVNPath destPath; if (sNewName.IsEmpty()) destPath = CTSVNPath(droppath+_T("\\")+pathList[nPath].GetFileOrDirectoryName()); else destPath = CTSVNPath(droppath+_T("\\")+sNewName); // path the same but case-changed is ok: results in a case-rename if (!(pathList[nPath].IsEquivalentToWithoutCase(destPath) && !pathList[nPath].IsEquivalentTo(destPath))) { if (destPath.Exists()) { CString name = pathList[nPath].GetFileOrDirectoryName(); if (!sNewName.IsEmpty()) name = sNewName; progress.Stop(); CRenameDlg dlg; dlg.SetInputValidator(this); dlg.m_name = name; dlg.m_windowtitle.Format(IDS_PROC_NEWNAMEMOVE, (LPCTSTR)name); if (dlg.DoModal() != IDOK) { return FALSE; } destPath.SetFromWin(droppath+_T("\\")+dlg.m_name); } } if (!svn.Move(CTSVNPathList(pathList[nPath]), destPath)) { if ((svn.GetSVNError() && svn.GetSVNError()->apr_err == SVN_ERR_ENTRY_EXISTS) && (destPath.Exists())) { if ((msgRet != IDYESTOALL) && (msgRet != IDNOTOALL)) { // target file already exists. Ask user if he wants to replace the file CString sReplace; sReplace.Format(IDS_PROC_REPLACEEXISTING, destPath.GetWinPath()); if (CTaskDialog::IsSupported()) { 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.SetVerificationCheckboxText(CString(MAKEINTRESOURCE(IDS_PROC_REPLACEEXISTING_TASK5))); taskdlg.SetVerificationCheckbox(false); taskdlg.SetDefaultCommandControl(2); taskdlg.SetMainIcon(TD_WARNING_ICON); INT_PTR ret = taskdlg.DoModal(GetExplorerHWND()); if (ret == 1) // replace msgRet = taskdlg.GetVerificationCheckboxState() ? IDYES : IDYESTOALL; else msgRet = taskdlg.GetVerificationCheckboxState() ? IDNO : IDNOTOALL; } else { msgRet = TSVNMessageBox(GetExplorerHWND(), sReplace, _T("TortoiseSVN"), MB_ICONQUESTION|MB_YESNO|MB_YESTOALL|MB_NOTOALL); } } if ((msgRet == IDYES) || (msgRet == IDYESTOALL)) { if (!svn.Remove(CTSVNPathList(destPath), true, false)) { destPath.Delete(true); } if (!svn.Move(CTSVNPathList(pathList[nPath]), destPath)) { svn.ShowErrorDialog(GetExplorerHWND(), pathList[nPath]); return FALSE; //get out of here } CShellUpdater::Instance().AddPathForUpdate(destPath); } } else { svn.ShowErrorDialog(GetExplorerHWND(), pathList[nPath]); return FALSE; //get out of here } } else CShellUpdater::Instance().AddPathForUpdate(destPath); count++; if (progress.IsValid()) { progress.FormatPathLine(1, IDS_PROC_MOVINGPROG, pathList[nPath].GetWinPath()); progress.FormatPathLine(2, IDS_PROC_CPYMVPROG2, destPath.GetWinPath()); progress.SetProgress(count, pathList.GetCount()); } if ((progress.IsValid())&&(progress.HasUserCancelled())) { TSVNMessageBox(GetExplorerHWND(), IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_ICONINFORMATION); return FALSE; } } return true; }
bool CSVNStatusCache::IsPathGood(const CTSVNPath& path) { AutoLocker lock(m_NoWatchPathCritSec); for (std::map<CTSVNPath, ULONGLONG>::const_iterator it = m_NoWatchPaths.begin(); it != m_NoWatchPaths.end(); ++it) { if (it->first.IsAncestorOf(path)) { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": path not good: %s\n", path.GetWinPath()); return false; } } return true; }
bool CheckoutCommand::Execute() { bool bRet = false; // Get the directory supplied in the command line. If there isn't // one then we should use first the default checkout path // specified in the settings dialog, and fall back to the current // working directory instead if no such path was specified. CTSVNPath checkoutDirectory; CRegString regDefCheckoutPath(_T("Software\\TortoiseSVN\\DefaultCheckoutPath")); if (cmdLinePath.IsEmpty()) { if (CString(regDefCheckoutPath).IsEmpty()) { checkoutDirectory.SetFromWin(sOrigCWD, true); DWORD len = ::GetTempPath(0, NULL); std::unique_ptr<TCHAR[]> tszPath(new TCHAR[len]); ::GetTempPath(len, tszPath.get()); if (_tcsncicmp(checkoutDirectory.GetWinPath(), tszPath.get(), len-2 /* \\ and \0 */) == 0) { // if the current directory is set to a temp directory, // we don't use that but leave it empty instead. checkoutDirectory.Reset(); } } else { checkoutDirectory.SetFromWin(CString(regDefCheckoutPath)); } } else { checkoutDirectory = cmdLinePath; } CCheckoutDlg dlg; dlg.m_URLs.LoadFromAsteriskSeparatedString (parser.GetVal(_T("url"))); if (dlg.m_URLs.GetCount()==0) { SVN svn; if (svn.IsRepository(cmdLinePath)) { CString url; // The path points to a local repository. // Add 'file:///' so the repository browser recognizes // it as an URL to the local repository. if (cmdLinePath.GetWinPathString().GetAt(0) == '\\') // starts with '\' means an UNC path { CString p = cmdLinePath.GetWinPathString(); p.TrimLeft('\\'); url = _T("file://")+p; } else url = _T("file:///")+cmdLinePath.GetWinPathString(); url.Replace('\\', '/'); dlg.m_URLs.AddPath(CTSVNPath(url)); checkoutDirectory.AppendRawString(L"wc"); } } dlg.m_strCheckoutDirectory = checkoutDirectory.GetWinPathString(); // if there is no url specified on the command line, check if there's one // specified in the settings dialog to use as the default and use that CRegString regDefCheckoutUrl(_T("Software\\TortoiseSVN\\DefaultCheckoutUrl")); if (!CString(regDefCheckoutUrl).IsEmpty()) { // if the URL specified is a child of the default URL, we also // adjust the default checkout path // e.g. // Url specified on command line: http://server.com/repos/project/trunk/folder // Url specified as default : http://server.com/repos/project/trunk // checkout path specified : c:\work\project // --> // checkout path adjusted : c:\work\project\folder CTSVNPath clurl = dlg.m_URLs.GetCommonDirectory(); CTSVNPath defurl = CTSVNPath(CString(regDefCheckoutUrl)); if (defurl.IsAncestorOf(clurl)) { // the default url is the parent of the specified url if (CTSVNPath::CheckChild(CTSVNPath(CString(regDefCheckoutPath)), CTSVNPath(dlg.m_strCheckoutDirectory))) { dlg.m_strCheckoutDirectory = CString(regDefCheckoutPath) + clurl.GetWinPathString().Mid(defurl.GetWinPathString().GetLength()); dlg.m_strCheckoutDirectory.Replace(_T("\\\\"), _T("\\")); } } if (dlg.m_URLs.GetCount() == 0) dlg.m_URLs.AddPath (defurl); } for (int i = 0; i < dlg.m_URLs.GetCount(); ++i) { CString pathString = dlg.m_URLs[i].GetWinPathString(); if (pathString.Left(5).Compare(_T("tsvn:"))==0) { pathString = pathString.Mid(5); if (pathString.Find('?') >= 0) { dlg.Revision = SVNRev(pathString.Mid(pathString.Find('?')+1)); pathString = pathString.Left(pathString.Find('?')); } } dlg.m_URLs[i].SetFromWin (pathString); } if (parser.HasKey(_T("revision"))) { SVNRev Rev = SVNRev(parser.GetVal(_T("revision"))); dlg.Revision = Rev; } dlg.m_blockPathAdjustments = parser.HasKey(L"blockpathadjustments"); if (dlg.DoModal() == IDOK) { checkoutDirectory.SetFromWin(dlg.m_strCheckoutDirectory, true); CSVNProgressDlg progDlg; theApp.m_pMainWnd = &progDlg; bool useStandardCheckout = dlg.m_standardCheckout || ((dlg.m_URLs.GetCount() > 1) && dlg.m_bIndependentWCs); progDlg.SetCommand (useStandardCheckout ? dlg.m_checkoutDepths.size() ? CSVNProgressDlg::SVNProgress_SparseCheckout : CSVNProgressDlg::SVNProgress_Checkout : dlg.m_parentExists && (dlg.m_URLs.GetCount() == 1) ? CSVNProgressDlg::SVNProgress_Update : CSVNProgressDlg::SVNProgress_SingleFileCheckout); if (dlg.m_checkoutDepths.size()) progDlg.SetPathDepths(dlg.m_checkoutDepths); progDlg.SetAutoClose (parser); progDlg.SetOptions(dlg.m_bNoExternals ? ProgOptIgnoreExternals : ProgOptNone); progDlg.SetPathList(CTSVNPathList(checkoutDirectory)); progDlg.SetUrl(dlg.m_URLs.CreateAsteriskSeparatedString()); progDlg.SetRevision(dlg.Revision); progDlg.SetDepth(dlg.m_depth); progDlg.DoModal(); bRet = !progDlg.DidErrorsOccur(); } return bRet; }
unsigned int __stdcall CommandThread(LPVOID lpvParam) { CCrashReportThread crashthread; CTraceToOutputDebugString::Instance()(__FUNCTION__ ": CommandThread started\n"); DWORD cbBytesRead; CAutoFile hPipe; // The thread's parameter is a handle to a pipe instance. hPipe = std::move((HANDLE) lpvParam); while (bRun) { // Read client requests from the pipe. TSVNCacheCommand command; BOOL fSuccess = ReadFile( hPipe, // handle to pipe &command, // buffer to receive data sizeof(command), // size of buffer &cbBytesRead, // number of bytes read NULL); // not overlapped I/O if (! fSuccess || cbBytesRead == 0) { DisconnectNamedPipe(hPipe); CTraceToOutputDebugString::Instance()(__FUNCTION__ ": Command thread exited\n"); return 1; } // sanitize request: // * Make sure the string properly 0-terminated // by resetting overlong paths to the empty string // * Set all trailing chars to 0. // This is more or less paranoia code but maybe something // is feeding garbage into our queue. for (size_t i = MAX_PATH+1; (i > 0) && (command.path[i-1] != 0); --i) command.path[i-1] = 0; size_t pathLength = wcslen (command.path); SecureZeroMemory ( command.path + pathLength , sizeof (command.path) - pathLength * sizeof (TCHAR)); // process request switch (command.command) { case TSVNCACHECOMMAND_END: FlushFileBuffers(hPipe); DisconnectNamedPipe(hPipe); CTraceToOutputDebugString::Instance()(__FUNCTION__ ": Command thread exited\n"); return 0; case TSVNCACHECOMMAND_CRAWL: { CTSVNPath changedpath; changedpath.SetFromWin(command.path, true); // remove the path from our cache - that will 'invalidate' it. { CAutoWriteLock writeLock(CSVNStatusCache::Instance().GetGuard()); CSVNStatusCache::Instance().RemoveCacheForPath(changedpath); } CSVNStatusCache::Instance().AddFolderForCrawling(changedpath.GetDirectory()); } break; case TSVNCACHECOMMAND_REFRESHALL: { CAutoWriteLock writeLock(CSVNStatusCache::Instance().GetGuard()); CSVNStatusCache::Instance().Refresh(); } break; case TSVNCACHECOMMAND_RELEASE: { CTSVNPath changedpath; changedpath.SetFromWin(command.path, true); CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": release handle for path %s\n", changedpath.GetWinPath()); CAutoWriteLock writeLock(CSVNStatusCache::Instance().GetGuard()); CSVNStatusCache::Instance().CloseWatcherHandles(changedpath); CSVNStatusCache::Instance().RemoveCacheForPath(changedpath); } break; case TSVNCACHECOMMAND_BLOCK: { CTSVNPath changedpath; changedpath.SetFromWin(command.path); CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": block path %s\n", changedpath.GetWinPath()); CSVNStatusCache::Instance().BlockPath(changedpath, false); } break; case TSVNCACHECOMMAND_UNBLOCK: { CTSVNPath changedpath; changedpath.SetFromWin(command.path); CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": unblock path %s\n", changedpath.GetWinPath()); CSVNStatusCache::Instance().UnBlockPath(changedpath); } break; } } // Flush the pipe to allow the client to read the pipe's contents // before disconnecting. Then disconnect the pipe, and close the // handle to this pipe instance. FlushFileBuffers(hPipe); DisconnectNamedPipe(hPipe); CTraceToOutputDebugString::Instance()(__FUNCTION__ ": Command thread exited\n"); return 0; }
void CCopyDlg::OnLvnGetdispinfoExternalslist(NMHDR *pNMHDR, LRESULT *pResult) { NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR); *pResult = 0; if (m_ExtList.HasText()) return; if (pDispInfo) { if (pDispInfo->item.iItem < (int)m_externals.size()) { SVNExternal ext = m_externals[pDispInfo->item.iItem]; if (pDispInfo->item.mask & LVIF_INDENT) { pDispInfo->item.iIndent = 0; } if (pDispInfo->item.mask & LVIF_IMAGE) { pDispInfo->item.mask |= LVIF_STATE; pDispInfo->item.stateMask = LVIS_STATEIMAGEMASK; if (ext.adjust) { //Turn check box on pDispInfo->item.state = INDEXTOSTATEIMAGEMASK(2); } else { //Turn check box off pDispInfo->item.state = INDEXTOSTATEIMAGEMASK(1); } } if (pDispInfo->item.mask & LVIF_TEXT) { switch (pDispInfo->item.iSubItem) { case 0: // folder { CTSVNPath p = ext.path; p.AppendPathString(ext.targetDir); lstrcpyn(m_columnbuf, p.GetWinPath(), min(MAX_PATH-2, pDispInfo->item.cchTextMax)); int cWidth = m_ExtList.GetColumnWidth(0); cWidth = max(28, cWidth-28); CDC * pDC = m_ExtList.GetDC(); if (pDC != NULL) { CFont * pFont = pDC->SelectObject(m_ExtList.GetFont()); PathCompactPath(pDC->GetSafeHdc(), m_columnbuf, cWidth); pDC->SelectObject(pFont); ReleaseDC(pDC); } } break; case 1: // url { lstrcpyn(m_columnbuf, ext.url, min(MAX_PATH-2, pDispInfo->item.cchTextMax)); SVNRev peg(ext.pegrevision); if (peg.IsValid() && !peg.IsHead()) { wcscat_s(m_columnbuf, L"@"); wcscat_s(m_columnbuf, peg.ToString()); } int cWidth = m_ExtList.GetColumnWidth(1); cWidth = max(14, cWidth-14); CDC * pDC = m_ExtList.GetDC(); if (pDC != NULL) { CFont * pFont = pDC->SelectObject(m_ExtList.GetFont()); PathCompactPath(pDC->GetSafeHdc(), m_columnbuf, cWidth); pDC->SelectObject(pFont); ReleaseDC(pDC); } } break; case 2: // tagged m_columnbuf[0] = 0; if (ext.origrevision.kind == svn_opt_revision_number) swprintf_s(m_columnbuf, L"%ld", ext.origrevision.value.number); else if (ext.origrevision.kind == svn_opt_revision_date) { SVNRev r(ext.origrevision); wcscpy_s(m_columnbuf, (LPCTSTR)r.ToString()); } break; default: m_columnbuf[0] = 0; } pDispInfo->item.pszText = m_columnbuf; } } } }
void CDirectoryWatcher::WorkerThread() { DWORD numBytes; CDirWatchInfo * pdi = NULL; LPOVERLAPPED lpOverlapped; WCHAR buf[READ_DIR_CHANGE_BUFFER_SIZE] = {0}; WCHAR * pFound = NULL; while (m_bRunning) { CleanupWatchInfo(); if (watchedPaths.GetCount()) { // Any incoming notifications? pdi = NULL; numBytes = 0; InterlockedExchange(&m_bCleaned, FALSE); if ( (!m_hCompPort) || !GetQueuedCompletionStatus(m_hCompPort, &numBytes, (PULONG_PTR) &pdi, &lpOverlapped, 600000 /*10 minutes*/)) { // No. Still trying? if (!m_bRunning) return; CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": restarting watcher\n"); m_hCompPort.CloseHandle(); // We must sync the whole section because other threads may // receive "AddPath" calls that will delete the completion // port *while* we are adding references to it . AutoLocker lock(m_critSec); // Clear the list of watched objects and recreate that list. // This will also delete the old completion port ClearInfoMap(); CleanupWatchInfo(); for (int i=0; i<watchedPaths.GetCount(); ++i) { CTSVNPath watchedPath = watchedPaths[i]; CAutoFile hDir = CreateFile(watchedPath.GetWinPath(), FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, //security attributes OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | //required privileges: SE_BACKUP_NAME and SE_RESTORE_NAME. FILE_FLAG_OVERLAPPED, NULL); if (!hDir) { // this could happen if a watched folder has been removed/renamed CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": CreateFile failed. Can't watch directory %s\n", watchedPaths[i].GetWinPath()); watchedPaths.RemovePath(watchedPath); break; } DEV_BROADCAST_HANDLE NotificationFilter; SecureZeroMemory(&NotificationFilter, sizeof(NotificationFilter)); NotificationFilter.dbch_size = sizeof(DEV_BROADCAST_HANDLE); NotificationFilter.dbch_devicetype = DBT_DEVTYP_HANDLE; NotificationFilter.dbch_handle = hDir; // RegisterDeviceNotification sends a message to the UI thread: // make sure we *can* send it and that the UI thread isn't waiting on a lock int numPaths = watchedPaths.GetCount(); size_t numWatch = watchInfoMap.size(); lock.Unlock(); NotificationFilter.dbch_hdevnotify = RegisterDeviceNotification(hWnd, &NotificationFilter, DEVICE_NOTIFY_WINDOW_HANDLE); lock.Lock(); // since we released the lock to prevent a deadlock with the UI thread, // it could happen that new paths were added to watch, or another thread // could have cleared our info map. // if that happened, we have to restart watching all paths again. if ((numPaths != watchedPaths.GetCount()) || (numWatch != watchInfoMap.size())) { ClearInfoMap(); CleanupWatchInfo(); Sleep(200); break; } CDirWatchInfo * pDirInfo = new CDirWatchInfo(hDir, watchedPath); hDir.Detach(); // the new CDirWatchInfo object owns the handle now pDirInfo->m_hDevNotify = NotificationFilter.dbch_hdevnotify; HANDLE port = CreateIoCompletionPort(pDirInfo->m_hDir, m_hCompPort, (ULONG_PTR)pDirInfo, 0); if (port == NULL) { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": CreateIoCompletionPort failed. Can't watch directory %s\n", watchedPath.GetWinPath()); // we must close the directory handle to allow ClearInfoMap() // to close the completion port properly pDirInfo->CloseDirectoryHandle(); ClearInfoMap(); CleanupWatchInfo(); delete pDirInfo; pDirInfo = NULL; watchedPaths.RemovePath(watchedPath); break; } m_hCompPort = port; if (!ReadDirectoryChangesW(pDirInfo->m_hDir, pDirInfo->m_Buffer, READ_DIR_CHANGE_BUFFER_SIZE, TRUE, FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE, &numBytes,// not used &pDirInfo->m_Overlapped, NULL)) //no completion routine! { CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": ReadDirectoryChangesW failed. Can't watch directory %s\n", watchedPath.GetWinPath()); // we must close the directory handle to allow ClearInfoMap() // to close the completion port properly pDirInfo->CloseDirectoryHandle(); ClearInfoMap(); CleanupWatchInfo(); delete pDirInfo; pDirInfo = NULL; watchedPaths.RemovePath(watchedPath); break; } CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": watching path %s\n", pDirInfo->m_DirName.GetWinPath()); watchInfoMap[pDirInfo->m_hDir] = pDirInfo; } } else { if (!m_bRunning) return; if (watchInfoMap.empty()) continue; // NOTE: the longer this code takes to execute until ReadDirectoryChangesW // is called again, the higher the chance that we miss some // changes in the file system! if (pdi) { BOOL bRet = false; std::list<CTSVNPath> notifyPaths; { AutoLocker lock(m_critSec); // in case the CDirectoryWatcher objects have been cleaned, // the m_bCleaned variable will be set to true here. If the // objects haven't been cleared, we can access them here. if (InterlockedExchange(&m_bCleaned, FALSE)) continue; if ( (!pdi->m_hDir) || watchInfoMap.empty() || (watchInfoMap.find(pdi->m_hDir) == watchInfoMap.end())) { continue; } PFILE_NOTIFY_INFORMATION pnotify = (PFILE_NOTIFY_INFORMATION)pdi->m_Buffer; DWORD nOffset = 0; do { pnotify = (PFILE_NOTIFY_INFORMATION)((LPBYTE)pnotify + nOffset); if ((ULONG_PTR)pnotify - (ULONG_PTR)pdi->m_Buffer > READ_DIR_CHANGE_BUFFER_SIZE) break; nOffset = pnotify->NextEntryOffset; if (pnotify->FileNameLength >= (READ_DIR_CHANGE_BUFFER_SIZE*sizeof(TCHAR))) continue; SecureZeroMemory(buf, READ_DIR_CHANGE_BUFFER_SIZE*sizeof(TCHAR)); wcsncpy_s(buf, pdi->m_DirPath, _countof(buf)-1); errno_t err = wcsncat_s(buf+pdi->m_DirPath.GetLength(), READ_DIR_CHANGE_BUFFER_SIZE-pdi->m_DirPath.GetLength(), pnotify->FileName, min(READ_DIR_CHANGE_BUFFER_SIZE-pdi->m_DirPath.GetLength(), int(pnotify->FileNameLength/sizeof(TCHAR)))); if (err == STRUNCATE) { continue; } buf[(pnotify->FileNameLength/sizeof(TCHAR))+pdi->m_DirPath.GetLength()] = 0; if (m_FolderCrawler) { if ((pFound = StrStrI(buf, L"\\tmp"))!=NULL) { pFound += 4; if (((*pFound)=='\\')||((*pFound)=='\0')) { continue; } } if ((pFound = StrStrI(buf, L":\\RECYCLER"))!=NULL) { if ((*(pFound + 10) == '\0') || (*(pFound + 10) == '\\')) continue; } if ((pFound = StrStrI(buf, L":\\$Recycle.Bin"))!=NULL) { if ((*(pFound + 14) == '\0') || (*(pFound + 14) == '\\')) continue; } if (StrStrI(buf, L".tmp")!=NULL) { // assume files with a .tmp extension are not versioned and interesting, // so ignore them. continue; } CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": change notification for %s\n", buf); notifyPaths.push_back(CTSVNPath(buf)); } } while ((nOffset > 0)&&(nOffset < READ_DIR_CHANGE_BUFFER_SIZE)); // setup next notification cycle SecureZeroMemory (pdi->m_Buffer, sizeof(pdi->m_Buffer)); SecureZeroMemory (&pdi->m_Overlapped, sizeof(OVERLAPPED)); bRet = ReadDirectoryChangesW (pdi->m_hDir, pdi->m_Buffer, READ_DIR_CHANGE_BUFFER_SIZE, TRUE, FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE, &numBytes,// not used &pdi->m_Overlapped, NULL); //no completion routine! } if (!notifyPaths.empty()) { for (auto nit = notifyPaths.cbegin(); nit != notifyPaths.cend(); ++nit) { m_FolderCrawler->AddPathForUpdate(*nit); } } // any clean-up to do? CleanupWatchInfo(); if (!bRet) { // Since the call to ReadDirectoryChangesW failed, just // wait a while. We don't want to have this thread // running using 100% CPU if something goes completely // wrong. Sleep(200); } } } }// if (watchedPaths.GetCount()) else Sleep(200); }// while (m_bRunning) }
bool DropExternalCommand::Execute() { bool bSuccess = false; CString droppath = parser.GetVal(L"droptarget"); CTSVNPath droptsvnpath = CTSVNPath(droppath); if (droptsvnpath.IsAdminDir()) droptsvnpath = droptsvnpath.GetDirectory(); if (!droptsvnpath.IsDirectory()) droptsvnpath = droptsvnpath.GetDirectory(); // first get the svn:externals property from the target folder SVNProperties props(droptsvnpath, SVNRev::REV_WC, false, false); std::string sExternalsValue; for (int i = 0; i < props.GetCount(); ++i) { if (props.GetItemName(i).compare(SVN_PROP_EXTERNALS) == 0) { sExternalsValue = props.GetItemValue(i); break; } } // we don't add admin dirs as externals pathList.RemoveAdminPaths(); if (pathList.GetCount() == 0) return bSuccess; SVNStatus status; status.GetStatus(droptsvnpath); CString sTargetRepoRootUrl; if (status.status && status.status->repos_root_url) { sTargetRepoRootUrl = CUnicodeUtils::GetUnicode(status.status->repos_root_url); } if (sTargetRepoRootUrl.IsEmpty()) { // failed to get the status and/or the repo root url CString messageString; messageString.Format(IDS_ERR_NOURLOFFILE, droptsvnpath.GetWinPath()); ::MessageBox(GetExplorerHWND(), messageString, L"TortoiseSVN", MB_ICONERROR); } SVN svn; for (auto i = 0; i < pathList.GetCount(); ++i) { CTSVNPath destPath = droptsvnpath; destPath.AppendPathString(pathList[i].GetFileOrDirectoryName()); bool bExists = !!PathFileExists(destPath.GetWinPath()); if (!bExists && (PathIsDirectory(pathList[i].GetWinPath()) || CopyFile(pathList[i].GetWinPath(), destPath.GetWinPath(), TRUE))) { SVNStatus sourceStatus; sourceStatus.GetStatus(pathList[i]); if (sourceStatus.status && sourceStatus.status->repos_root_url) { CString sExternalRootUrl = CUnicodeUtils::GetUnicode(sourceStatus.status->repos_root_url); CString sExternalUrl = svn.GetURLFromPath(pathList[i]); CString sExtValue = sExternalUrl + L" " + pathList[i].GetFileOrDirectoryName(); // check if the url is from the same repo as the target, and if it is // use a relative external url instead of a full url if (sTargetRepoRootUrl.Compare(sExternalRootUrl) == 0) { sExtValue = L"^" + sExternalUrl.Mid(sTargetRepoRootUrl.GetLength()) + L" " + pathList[i].GetFileOrDirectoryName(); } if (!sExternalsValue.empty()) { if (sExternalsValue[sExternalsValue.size() - 1] != '\n') sExternalsValue += "\n"; } sExternalsValue += CUnicodeUtils::StdGetUTF8((LPCWSTR)sExtValue); bSuccess = true; } } else { // the file already exists, there can't be an external with the // same name. CString messageString; messageString.Format(IDS_DROPEXT_FILEEXISTS, (LPCWSTR)pathList[i].GetFileOrDirectoryName()); ::MessageBox(GetExplorerHWND(), messageString, L"TortoiseSVN", MB_ICONERROR); bSuccess = false; } } if (bSuccess) { bSuccess = !!props.Add(SVN_PROP_EXTERNALS, sExternalsValue, true); if (bSuccess) { CString sInfo; sInfo.Format(IDS_DROPEXT_UPDATE_TASK1, (LPCTSTR)droptsvnpath.GetFileOrDirectoryName()); CTaskDialog taskdlg(sInfo, CString(MAKEINTRESOURCE(IDS_DROPEXT_UPDATE_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_DROPEXT_UPDATE_TASK3))); taskdlg.AddCommandControl(2, CString(MAKEINTRESOURCE(IDS_DROPEXT_UPDATE_TASK4))); taskdlg.SetCommonButtons(TDCBF_CANCEL_BUTTON); taskdlg.SetDefaultCommandControl(2); taskdlg.SetMainIcon(TD_WARNING_ICON); bool doUpdate = (taskdlg.DoModal(GetExplorerHWND()) == 1); if (doUpdate) { DWORD exitcode = 0; CString error; ProjectProperties pprops; pprops.ReadPropsPathList(pathList); CHooks::Instance().SetProjectProperties(droptsvnpath, pprops); if (CHooks::Instance().StartUpdate(GetExplorerHWND(), pathList, exitcode, error)) { if (exitcode) { CString temp; temp.Format(IDS_ERR_HOOKFAILED, (LPCTSTR)error); ::MessageBox(GetExplorerHWND(), temp, L"TortoiseSVN", MB_ICONERROR); return FALSE; } } CSVNProgressDlg progDlg; theApp.m_pMainWnd = &progDlg; progDlg.SetCommand(CSVNProgressDlg::SVNProgress_Update); progDlg.SetAutoClose(parser); progDlg.SetOptions(ProgOptSkipPreChecks); progDlg.SetPathList(CTSVNPathList(droptsvnpath)); progDlg.SetRevision(SVNRev(L"HEAD")); progDlg.SetProjectProperties(pprops); progDlg.SetDepth(svn_depth_unknown); progDlg.DoModal(); return !progDlg.DidErrorsOccur(); } } else { // adding the svn:externals property failed, remove all the copied files props.ShowErrorDialog(GetExplorerHWND()); } } return bSuccess != false; }
CStatusCacheEntry CSVNStatusCache::GetStatusForPath(const CTSVNPath& path, DWORD flags, bool bFetch /* = true */) { bool bRecursive = !!(flags & TSVNCACHE_FLAGS_RECUSIVE_STATUS); // Check a very short-lived 'mini-cache' of the last thing we were asked for. LONGLONG now = (LONGLONG)GetTickCount64(); if(now-m_mostRecentExpiresAt < 0) { if(path.IsEquivalentToWithoutCase(m_mostRecentAskedPath)) { return m_mostRecentStatus; } } { AutoLocker lock(m_critSec); m_mostRecentAskedPath = path; m_mostRecentExpiresAt = now+1000; } if (m_shellCache.IsPathAllowed(path.GetWinPath())) { if (IsPathGood(path)) { // Stop the crawler starting on a new folder while we're doing this much more important task... // Please note, that this may be a second "lock" used concurrently to the one in RemoveCacheForPath(). CCrawlInhibitor crawlInhibit(&m_folderCrawler); CTSVNPath dirpath = path.GetContainingDirectory(); if (dirpath.IsEmpty()) dirpath = path.GetDirectory(); CCachedDirectory * cachedDir = GetDirectoryCacheEntry(dirpath); if (cachedDir != NULL) { CStatusCacheEntry entry = cachedDir->GetStatusForMember(path, bRecursive, bFetch); { AutoLocker lock(m_critSec); m_mostRecentStatus = entry; return m_mostRecentStatus; } } cachedDir = GetDirectoryCacheEntry(path.GetDirectory()); if (cachedDir != NULL) { CStatusCacheEntry entry = cachedDir->GetStatusForMember(path, bRecursive, bFetch); { AutoLocker lock(m_critSec); m_mostRecentStatus = entry; return m_mostRecentStatus; } } } else { // path is blocked for some reason: return the cached status if we have one // we do here only a cache search, absolutely no disk access is allowed! CCachedDirectory::ItDir itMap = m_directoryCache.find(path); if ((itMap != m_directoryCache.end())&&(itMap->second)) { // We've found this directory in the cache CCachedDirectory * cachedDir = itMap->second; CStatusCacheEntry entry = cachedDir->GetCacheStatusForMember(path); { AutoLocker lock(m_critSec); m_mostRecentStatus = entry; return m_mostRecentStatus; } } } } AutoLocker lock(m_critSec); m_mostRecentStatus = CStatusCacheEntry(); if (m_shellCache.ShowExcludedAsNormal() && path.IsDirectory() && m_shellCache.IsVersioned(path.GetWinPath(), true, true)) { m_mostRecentStatus.ForceStatus(svn_wc_status_normal); } return m_mostRecentStatus; }