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 }
int SVNPatch::Init( const CString& patchfile, const CString& targetpath, CProgressDlg *pPprogDlg ) { CTSVNPath target = CTSVNPath(targetpath); if (patchfile.IsEmpty() || targetpath.IsEmpty() || !svn_dirent_is_absolute(target.GetSVNApiPath(m_pool))) { m_errorStr.LoadString(IDS_ERR_PATCHPATHS); return 0; } svn_error_t * err = NULL; apr_pool_t * scratchpool = NULL; svn_client_ctx_t * ctx = NULL; m_errorStr.Empty(); m_patchfile = patchfile; m_targetpath = targetpath; m_testPath.Empty(); m_patchfile.Replace('\\', '/'); m_targetpath.Replace('\\', '/'); apr_pool_create_ex(&scratchpool, m_pool, abort_on_pool_failure, NULL); svn_error_clear(svn_client_create_context2(&ctx, SVNConfig::Instance().GetConfig(m_pool), scratchpool)); ctx->notify_func2 = notify; ctx->notify_baton2 = this; if (pPprogDlg) { pPprogDlg->SetTitle(IDS_APPNAME); pPprogDlg->FormatNonPathLine(1, IDS_PATCH_PROGTITLE); pPprogDlg->SetShowProgressBar(false); pPprogDlg->ShowModeless(AfxGetMainWnd()); m_pProgDlg = pPprogDlg; } m_filePaths.clear(); m_nRejected = 0; m_nStrip = 0; CTSVNPath tsvnpatchfile = CTSVNPath(m_patchfile); CTSVNPath tsvntargetpath = CTSVNPath(m_targetpath); err = svn_client_patch(tsvnpatchfile.GetSVNApiPath(scratchpool), // patch_abspath tsvntargetpath.GetSVNApiPath(scratchpool), // local_abspath true, // dry_run m_nStrip, // strip_count false, // reverse true, // ignore_whitespace false, // remove_tempfiles patch_func, // patch_func this, // patch_baton ctx, // client context scratchpool); m_pProgDlg = NULL; apr_pool_destroy(scratchpool); // since we're doing a dry-run, a 'path not found' can happen // since new files/dirs aren't added in the patch func. if ((err)&&(err->apr_err != SVN_ERR_WC_PATH_NOT_FOUND)) { m_errorStr = GetErrorMessage(err); m_filePaths.clear(); svn_error_clear(err); return 0; } if ((m_nRejected > ((int)m_filePaths.size() / 3)) && !m_testPath.IsEmpty()) { m_nStrip++; bool found = false; for (m_nStrip = 0; m_nStrip < STRIP_LIMIT; ++m_nStrip) { for (std::vector<PathRejects>::iterator it = m_filePaths.begin(); it != m_filePaths.end(); ++it) { if (Strip(it->path).IsEmpty()) { found = true; m_nStrip--; break; } } if (found) break; } } if (m_nStrip == STRIP_LIMIT) m_filePaths.clear(); else if (m_nStrip > 0) { apr_pool_create_ex(&scratchpool, m_pool, abort_on_pool_failure, NULL); svn_error_clear(svn_client_create_context2(&ctx, SVNConfig::Instance().GetConfig(m_pool), scratchpool)); ctx->notify_func2 = notify; ctx->notify_baton2 = this; m_filePaths.clear(); m_nRejected = 0; err = svn_client_patch(CUnicodeUtils::GetUTF8(m_patchfile), // patch_abspath CUnicodeUtils::GetUTF8(m_targetpath), // local_abspath true, // dry_run m_nStrip, // strip_count false, // reverse true, // ignore_whitespace false, // remove_tempfiles patch_func, // patch_func this, // patch_baton ctx, // client context scratchpool); apr_pool_destroy(scratchpool); if (err) { m_errorStr = GetErrorMessage(err); m_filePaths.clear(); svn_error_clear(err); } } return (int)m_filePaths.size(); }