OSDN Git Service

Show Bug ID link at log dialog
authorFrank Li <lznuaa@gmail.com>
Mon, 1 Jun 2009 02:04:25 +0000 (10:04 +0800)
committerFrank Li <lznuaa@gmail.com>
Mon, 1 Jun 2009 02:04:25 +0000 (10:04 +0800)
Signed-off-by: Frank Li <lznuaa@gmail.com>
src/TortoiseProc/LogDlg.cpp
src/TortoiseProc/ProjectProperties.cpp
src/TortoiseProc/ProjectProperties.h

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