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::UnifiedDiff(CTSVNPath& tempfile, const CTSVNPath& url1, const SVNRev& rev1, const CTSVNPath& url2, const SVNRev& rev2, const SVNRev& peg, const CString& options, bool bIgnoreAncestry /* = false */, bool bIgnoreProperties /* = true */) { tempfile = CTempFiles::Instance().GetTempFilePath(m_bRemoveTempFiles, CTSVNPath(L"Test.diff")); bool bIsUrl = !!SVN::PathIsURL(url1); CProgressDlg progDlg; progDlg.SetTitle(IDS_APPNAME); progDlg.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROGRESS_UNIFIEDDIFF))); progDlg.SetTime(false); m_pSVN->SetAndClearProgressInfo(&progDlg); progDlg.ShowModeless(GetHWND()); // find the root of the files CTSVNPathList plist; plist.AddPath(url1); plist.AddPath(url2); CTSVNPath relativeTo = plist.GetCommonRoot(); if (!relativeTo.IsUrl()) { if (!relativeTo.IsDirectory()) relativeTo = relativeTo.GetContainingDirectory(); } if (relativeTo.IsEmpty() && url1.Exists() && url2.IsUrl()) { // the source path exists, i.e. it's a local path, so // use this as the relative url relativeTo = url1.GetDirectory(); } // the 'relativeTo' path must be a path: svn throws an error if it's used for urls. else if ((!url2.IsEquivalentTo(url1) && (relativeTo.IsEquivalentTo(url1) || relativeTo.IsEquivalentTo(url2))) || url1.IsUrl() || url2.IsUrl()) relativeTo.Reset(); if ((!url1.IsEquivalentTo(url2))||((rev1.IsWorking() || rev1.IsBase())&&(rev2.IsWorking() || rev2.IsBase()))) { if (!m_pSVN->Diff(url1, rev1, url2, rev2, relativeTo, svn_depth_infinity, true, false, false, false, false, false, bIgnoreProperties, false, options, bIgnoreAncestry, tempfile)) { progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); m_pSVN->ShowErrorDialog(GetHWND()); return false; } } else { if (!m_pSVN->PegDiff(url1, (peg.IsValid() ? peg : (bIsUrl ? m_headPeg : SVNRev::REV_WC)), rev1, rev2, relativeTo, svn_depth_infinity, true, false, false, false, false, false, bIgnoreProperties, false, options, false, tempfile)) { if (!m_pSVN->Diff(url1, rev1, url2, rev2, relativeTo, svn_depth_infinity, true, false, false, false, false, false, bIgnoreProperties, false, options, false, tempfile)) { progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); m_pSVN->ShowErrorDialog(GetHWND()); return false; } } } if (CAppUtils::CheckForEmptyDiff(tempfile)) { progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); TaskDialog(GetHWND(), AfxGetResourceHandle(), MAKEINTRESOURCE(IDS_APPNAME), MAKEINTRESOURCE(IDS_ERR_ERROROCCURED), MAKEINTRESOURCE(IDS_ERR_EMPTYDIFF), TDCBF_OK_BUTTON, TD_ERROR_ICON, NULL); return false; } progDlg.Stop(); m_pSVN->SetAndClearProgressInfo((HWND)NULL); return true; }