From: Frank Li Date: Mon, 1 Jun 2009 02:04:25 +0000 (+0800) Subject: Show Bug ID link at log dialog X-Git-Url: http://git.sourceforge.jp/view?p=tortoisegit%2FTortoiseGitJp.git;a=commitdiff_plain;h=d49ae89bc2bf6529b7286ee9129690b13729b524 Show Bug ID link at log dialog Signed-off-by: Frank Li --- diff --git a/src/TortoiseProc/LogDlg.cpp b/src/TortoiseProc/LogDlg.cpp index 2a209e8..35276ce 100644 --- a/src/TortoiseProc/LogDlg.cpp +++ b/src/TortoiseProc/LogDlg.cpp @@ -515,10 +515,17 @@ void CLogDlg::FillLogMessageCtrl(bool bShow /* = true*/) }else { // set the log message text - pMsgView->SetWindowText(_T("Commit:")+pLogEntry->m_CommitHash+_T("\r\n\r\n*")+pLogEntry->m_Subject+_T("\n\n")+pLogEntry->m_Body); + pMsgView->SetWindowText(_T("Commit:")+pLogEntry->m_CommitHash+_T("\r\n\r\n* ")+pLogEntry->m_Subject+_T("\n\n")+pLogEntry->m_Body); // turn bug ID's into links if the bugtraq: properties have been set // and we can find a match of those in the log message - m_ProjectProperties.FindBugID(pLogEntry->m_Body, pMsgView); + + CString text; + pMsgView->GetWindowText(text); + // the rich edit control doesn't count the CR char! + // to be exact: CRLF is treated as one char. + text.Replace(_T("\r"), _T("")); + + m_ProjectProperties.FindBugID(text, pMsgView); CAppUtils::FormatTextInRichEditControl(pMsgView); int HidePaths=m_cHidePaths.GetState() & 0x0003; diff --git a/src/TortoiseProc/ProjectProperties.cpp b/src/TortoiseProc/ProjectProperties.cpp index 75d6687..3cf7830 100644 --- a/src/TortoiseProc/ProjectProperties.cpp +++ b/src/TortoiseProc/ProjectProperties.cpp @@ -1,4 +1,4 @@ -// TortoiseGit - a Windows shell extension for easy version control +// TortoiseSVN - a Windows shell extension for easy version control // Copyright (C) 2003-2008 - TortoiseGit @@ -98,6 +98,7 @@ BOOL ProjectProperties::ReadProps(CTGitPath path) GetStringProps(this->sLabel,BUGTRAQPROPNAME_LABEL); GetStringProps(this->sMessage,BUGTRAQPROPNAME_MESSAGE); + GetStringProps(this->sUrl,BUGTRAQPROPNAME_URL); GetBOOLProps(this->bWarnIfNoIssue,BUGTRAQPROPNAME_WARNIFNOISSUE); GetBOOLProps(this->bNumber,BUGTRAQPROPNAME_NUMBER); @@ -433,7 +434,7 @@ BOOL ProjectProperties::FindBugID(const CString& msg, CWnd * pWnd) { ATLTRACE(_T("matched id : %s\n"), (*it2)[0].str().c_str()); ptrdiff_t matchposID = it2->position(0); - CHARRANGE range = {matchpos+matchposID, matchpos+matchposID+(*it2)[0].str().size()}; + CHARRANGE range = {(LONG)(matchpos+matchposID), (LONG)(matchpos+matchposID+(*it2)[0].str().size())}; pWnd->SendMessage(EM_EXSETSEL, NULL, (LPARAM)&range); CHARFORMAT2 format; SecureZeroMemory(&format, sizeof(CHARFORMAT2)); @@ -462,7 +463,7 @@ BOOL ProjectProperties::FindBugID(const CString& msg, CWnd * pWnd) if (match.size() >= 2) { ATLTRACE(_T("matched id : %s\n"), wstring(match[1]).c_str()); - CHARRANGE range = {match[1].first-s.begin(), match[1].second-s.begin()}; + CHARRANGE range = {(LONG)(match[1].first-s.begin()), (LONG)(match[1].second-s.begin())}; pWnd->SendMessage(EM_EXSETSEL, NULL, (LPARAM)&range); CHARFORMAT2 format; SecureZeroMemory(&format, sizeof(CHARFORMAT2)); @@ -554,14 +555,11 @@ BOOL ProjectProperties::FindBugID(const CString& msg, CWnd * pWnd) return FALSE; } -CString ProjectProperties::FindBugID(const CString& msg) +std::set ProjectProperties::FindBugIDs(const CString& msg) { size_t offset1 = 0; size_t offset2 = 0; bool bFound = false; - - CString sRet; - std::set bugIDs; // first use the checkre string to find bug ID's in the message @@ -618,7 +616,7 @@ CString ProjectProperties::FindBugID(const CString& msg) CString sLastPart; BOOL bTop = FALSE; if (sMessage.Find(_T("%BUGID%"))<0) - goto finish; + return bugIDs; sFirstPart = sMessage.Left(sMessage.Find(_T("%BUGID%"))); sLastPart = sMessage.Mid(sMessage.Find(_T("%BUGID%"))+7); CString sMsg = msg; @@ -650,10 +648,10 @@ CString ProjectProperties::FindBugID(const CString& msg) bTop = TRUE; } if (sBugLine.IsEmpty()) - goto finish; + return bugIDs; CString sBugIDPart = sBugLine.Mid(sFirstPart.GetLength(), sBugLine.GetLength() - sFirstPart.GetLength() - sLastPart.GetLength()); if (sBugIDPart.IsEmpty()) - goto finish; + return bugIDs; //the bug id part can contain several bug id's, separated by commas if (!bTop) offset1 = sMsg.GetLength() - sBugLine.GetLength() + sFirstPart.GetLength(); @@ -672,7 +670,16 @@ CString ProjectProperties::FindBugID(const CString& msg) CHARRANGE range = {(LONG)offset1, (LONG)offset2}; bugIDs.insert(msg.Mid(range.cpMin, range.cpMax-range.cpMin)); } -finish: + + return bugIDs; +} + +CString ProjectProperties::FindBugID(const CString& msg) +{ + CString sRet; + + std::set bugIDs = FindBugIDs(msg); + for (std::set::iterator it = bugIDs.begin(); it != bugIDs.end(); ++it) { sRet += *it; @@ -866,6 +873,32 @@ CString ProjectProperties::GetLogSummary(const CString& sMessage) return sRet; } +CString ProjectProperties::MakeShortMessage(const CString& message) +{ + bool bFoundShort = true; + CString sShortMessage = GetLogSummary(message); + if (sShortMessage.IsEmpty()) + { + bFoundShort = false; + sShortMessage = message; + } + // Remove newlines and tabs 'cause those are not shown nicely in the list control + sShortMessage.Replace(_T("\r"), _T("")); + sShortMessage.Replace(_T("\t"), _T(" ")); + + // Suppose the first empty line separates 'summary' from the rest of the message. + int found = sShortMessage.Find(_T("\n\n")); + // To avoid too short 'short' messages + // (e.g. if the message looks something like "Bugfix:\n\n*done this\n*done that") + // only use the empty newline as a separator if it comes after at least 15 chars. + if ((!bFoundShort)&&(found >= 15)) + { + sShortMessage = sShortMessage.Left(found); + } + sShortMessage.Replace('\n', ' '); + return sShortMessage; +} + #ifdef DEBUG static class PropTest { diff --git a/src/TortoiseProc/ProjectProperties.h b/src/TortoiseProc/ProjectProperties.h index 31ebca8..ad21796 100644 --- a/src/TortoiseProc/ProjectProperties.h +++ b/src/TortoiseProc/ProjectProperties.h @@ -84,6 +84,7 @@ public: BOOL FindBugID(const CString& msg, CWnd * pWnd); CString FindBugID(const CString& msg); + std::set FindBugIDs(const CString& msg); /** * Searches for the BugID inside a log message. If one is found, * that BugID is returned. If none is found, an empty string is returned. @@ -128,6 +129,12 @@ public: */ CString GetLogSummary(const CString& sMessage); + /** + * Transform the log message using \ref GetLogSummary and post-process it + * to be suitable for 1-line controls. + */ + CString MakeShortMessage(const CString& message); + /** * Returns the path from which the properties were read. */ @@ -165,6 +172,14 @@ public: log message instead of at the bottom. Default is TRUE */ BOOL bAppend; + /** the COM uuid of the bugtraq provider which implements the IBugTraqProvider + interface. */ + CString sProviderUuid; + + /** the parameters passed to the COM bugtraq provider which implements the + IBugTraqProvider interface */ + CString sProviderParams; + /** The number of chars the width marker should be shown at. If the property * is not set, then this value is 80 by default. */ int nLogWidthMarker; @@ -205,6 +220,11 @@ public: * is the first matching regex group. */ CString sLogSummaryRe; + + /** + * A regex string to extract revisions from a log message. + */ + CString sLogRevRegex; private: CString sAutoProps; CTGitPath propsPath;