OSDN Git Service

Enable Bug track plug-in support
authorFrank Li <lznuaa@gmail.com>
Sun, 31 May 2009 07:50:52 +0000 (15:50 +0800)
committerFrank Li <lznuaa@gmail.com>
Sun, 31 May 2009 07:50:52 +0000 (15:50 +0800)
Signed-off-by: Frank Li <lznuaa@gmail.com>
src/IBugTraqProvider/IBugTraqProvider.idl
src/IBugTraqProvider/IBugTraqProvider.vcproj
src/Resources/TortoiseProcENG.rc
src/TortoiseProc/CommitDlg.cpp
src/TortoiseProc/CommitDlg.h
src/TortoiseProc/Settings/SetBugTraqAdv.cpp
src/TortoiseProc/resource.h
src/Utils/BugTraqAssociations.cpp
src/Utils/BugTraqAssociations.h

index 6579283..bdb6a3f 100644 (file)
@@ -73,14 +73,35 @@ interface IBugTraqProvider2 : IBugTraqProvider
        HRESULT GetCommitMessage2 (\r
                [in] HWND hParentWnd,                                   // Parent window for your provider's UI.\r
                [in] BSTR parameters,                                   // Parameters for your provider.\r
-               [in] BSTR commonURL,                                    // the common url of the commit\r
+               [in] BSTR commonURL,                                    // the common url of all items in the commit dialog (checked or unchecked!), \r
+                                                                                               // with the url of the item that was selected to bring up the commit dialog having precedence.\r
                [in] BSTR commonRoot,\r
                [in] SAFEARRAY(BSTR) pathList,\r
                [in] BSTR originalMessage,                              // The text already present in the commit message.\r
                                                                                                // Your provider should include this text in the new message, where appropriate.\r
-               [out, retval] BSTR *newMessage                  // The new text for the commit message. This replaces the original message.\r
+               // you can assign custom revision properties to a commit by setting the next two params.\r
+               // note: both safearrays must be of the same length. For every property name there must be a property value!\r
+               [in] BSTR bugID,                                                // the content of the bugID field (if shown)\r
+               [out] BSTR * bugIDOut,                                  // modified content of the bugID field\r
+               [out] SAFEARRAY(BSTR) * revPropNames,   // a list of revision property names which are applied to the commit\r
+               [out] SAFEARRAY(BSTR) * revPropValues,  // a list of revision property values which are applied to the commit\r
+               [out, retval] BSTR * newMessage                 // The new text for the commit message. This replaces the original message.\r
        );                      \r
 \r
+       /** Called right before the commit dialog is dismissed. This is the last chance to reject\r
+        * a commit. You can check the commit log message here and return an error message if it does not\r
+        * match your specification. An empty error string means the commit is allowed.\r
+        */\r
+       HRESULT CheckCommit (\r
+               [in] HWND hParentWnd,\r
+               [in] BSTR parameters,\r
+               [in] BSTR commonURL,\r
+               [in] BSTR commonRoot,\r
+               [in] SAFEARRAY(BSTR) pathList,\r
+               [in] BSTR commitMessage,\r
+               [out, retval] BSTR * errorMessage\r
+               );\r
+\r
        HRESULT OnCommitFinished (\r
                [in] HWND hParentWnd,                                   // Parent window for any (error) UI that needs to be displayed.\r
                [in] BSTR commonRoot,                                   // The common root of all paths that got committed.\r
index d0df98a..bebd9e1 100644 (file)
                        />\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
+                               Optimization="2"\r
+                               EnableIntrinsicFunctions="true"\r
                                PreprocessorDefinitions="WIN32;NDEBUG;_LIB"\r
                                RuntimeLibrary="2"\r
                                EnableFunctionLevelLinking="true"\r
                        />\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
+                               Optimization="2"\r
+                               EnableIntrinsicFunctions="true"\r
                                PreprocessorDefinitions="WIN32;NDEBUG;_LIB"\r
                                RuntimeLibrary="2"\r
                                EnableFunctionLevelLinking="true"\r
index 234fdb2..f10231f 100644 (file)
Binary files a/src/Resources/TortoiseProcENG.rc and b/src/Resources/TortoiseProcENG.rc differ
index d7e189b..45c8beb 100644 (file)
@@ -21,7 +21,7 @@
 #include "CommitDlg.h"\r
 #include "DirFileEnum.h"\r
 //#include "GitConfig.h"\r
-//#include "GitProperties.h"\r
+#include "ProjectProperties.h"\r
 #include "MessageBox.h"\r
 #include "AppUtils.h"\r
 #include "PathUtils.h"\r
@@ -101,6 +101,7 @@ BEGIN_MESSAGE_MAP(CCommitDlg, CResizableStandAloneDialog)
        ON_STN_CLICKED(IDC_COMMITLABEL, &CCommitDlg::OnStnClickedCommitlabel)\r
     ON_BN_CLICKED(IDC_COMMIT_AMEND, &CCommitDlg::OnBnClickedCommitAmend)\r
     ON_BN_CLICKED(IDC_WHOLE_PROJECT, &CCommitDlg::OnBnClickedWholeProject)\r
+       ON_STN_CLICKED(IDC_BUGIDLABEL, &CCommitDlg::OnStnClickedBugidlabel)\r
 END_MESSAGE_MAP()\r
 \r
 BOOL CCommitDlg::OnInitDialog()\r
@@ -129,7 +130,8 @@ BOOL CCommitDlg::OnInitDialog()
        m_ListCtrl.SetBackgroundImage(IDI_COMMIT_BKG);\r
        \r
        //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);\r
-//     m_ProjectProperties.ReadPropsPathList(m_pathList);\r
+       m_ProjectProperties.ReadPropsPathList(m_pathList);\r
+\r
        m_cLogMessage.Init(m_ProjectProperties);\r
        m_cLogMessage.SetFont((CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));\r
        m_cLogMessage.RegisterContextMenuHandler(this);\r
@@ -143,11 +145,11 @@ BOOL CCommitDlg::OnInitDialog()
        \r
        m_SelectAll.SetCheck(BST_INDETERMINATE);\r
 \r
-#if 0\r
+\r
        CBugTraqAssociations bugtraq_associations;\r
        bugtraq_associations.Load();\r
 \r
-       if (bugtraq_associations.FindProvider(m_pathList, &m_bugtraq_association))\r
+       if (bugtraq_associations.FindProvider(g_Git.m_CurrentDir, &m_bugtraq_association))\r
        {\r
                GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);\r
                GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);\r
@@ -186,7 +188,6 @@ BOOL CCommitDlg::OnInitDialog()
                }\r
        }\r
        else\r
-#endif\r
        {\r
                GetDlgItem(IDC_BUGID)->ShowWindow(SW_HIDE);\r
                GetDlgItem(IDC_BUGIDLABEL)->ShowWindow(SW_HIDE);\r
@@ -1349,7 +1350,6 @@ void CCommitDlg::OnBnClickedHistory()
 \r
 void CCommitDlg::OnBnClickedBugtraqbutton()\r
 {\r
-#if 0\r
        m_tooltips.Pop();       // hide the tooltips\r
        CString sMsg = m_cLogMessage.GetText();\r
 \r
@@ -1357,7 +1357,7 @@ void CCommitDlg::OnBnClickedBugtraqbutton()
                return;\r
 \r
        BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();\r
-       BSTR commonRoot = SysAllocString(m_pathList.GetCommonRoot().GetDirectory().GetWinPath());\r
+       BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);\r
        SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_pathList.GetCount());\r
 \r
        for (LONG index = 0; index < m_pathList.GetCount(); ++index)\r
@@ -1365,28 +1365,68 @@ void CCommitDlg::OnBnClickedBugtraqbutton()
 \r
        BSTR originalMessage = sMsg.AllocSysString();\r
        BSTR temp = NULL;\r
+//     m_revProps.clear();\r
 \r
        // first try the IBugTraqProvider2 interface\r
        CComPtr<IBugTraqProvider2> pProvider2 = NULL;\r
        HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);\r
        if (SUCCEEDED(hr))\r
        {\r
-               CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();\r
-               BSTR repositoryRoot = common.AllocSysString();\r
-               if (FAILED(hr = pProvider2->GetCommitMessage2(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, originalMessage, &temp)))\r
+               //CString common = m_ListCtrl.GetCommonURL(false).GetGitPathString();\r
+               BSTR repositoryRoot = g_Git.m_CurrentDir.AllocSysString();\r
+               BSTR bugIDOut = NULL;\r
+               GetDlgItemText(IDC_BUGID, m_sBugID);\r
+               BSTR bugID = m_sBugID.AllocSysString();\r
+               SAFEARRAY * revPropNames = NULL;\r
+               SAFEARRAY * revPropValues = NULL;\r
+               if (FAILED(hr = pProvider2->GetCommitMessage2(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, originalMessage, bugID, &bugIDOut, &revPropNames, &revPropValues, &temp)))\r
                {\r
                        CString sErr;\r
                        sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), _com_error(hr).ErrorMessage());\r
                        CMessageBox::Show(m_hWnd, sErr, _T("TortoiseGit"), MB_ICONERROR);\r
                }\r
                else\r
+               {\r
+                       if (bugIDOut)\r
+                       {\r
+                               m_sBugID = bugIDOut;\r
+                               SysFreeString(bugIDOut);\r
+                               SetDlgItemText(IDC_BUGID, m_sBugID);\r
+                       }\r
+                       SysFreeString(bugID);\r
+                       SysFreeString(repositoryRoot);\r
                        m_cLogMessage.SetText(temp);\r
+                       BSTR HUGEP *pbRevNames;\r
+                       BSTR HUGEP *pbRevValues;\r
+\r
+                       HRESULT hr1 = SafeArrayAccessData(revPropNames, (void HUGEP**)&pbRevNames);\r
+                       if (SUCCEEDED(hr1))\r
+                       {\r
+                               HRESULT hr2 = SafeArrayAccessData(revPropValues, (void HUGEP**)&pbRevValues);\r
+                               if (SUCCEEDED(hr2))\r
+                               {\r
+                                       if (revPropNames->rgsabound->cElements == revPropValues->rgsabound->cElements)\r
+                                       {\r
+                                               for (ULONG i = 0; i < revPropNames->rgsabound->cElements; i++)\r
+                                               {\r
+//                                                     m_revProps[pbRevNames[i]] = pbRevValues[i];\r
+                                               }\r
+                                       }\r
+                                       SafeArrayUnaccessData(revPropValues);\r
+                               }\r
+                               SafeArrayUnaccessData(revPropNames);\r
+                       }\r
+                       if (revPropNames)\r
+                               SafeArrayDestroy(revPropNames);\r
+                       if (revPropValues)\r
+                               SafeArrayDestroy(revPropValues);\r
+               }\r
        }\r
        else\r
        {\r
                // if IBugTraqProvider2 failed, try IBugTraqProvider\r
                CComPtr<IBugTraqProvider> pProvider = NULL;\r
-               HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider);\r
+               hr = m_BugTraqProvider.QueryInterface(&pProvider);\r
                if (FAILED(hr))\r
                {\r
                        CString sErr;\r
@@ -1404,11 +1444,24 @@ void CCommitDlg::OnBnClickedBugtraqbutton()
                else\r
                        m_cLogMessage.SetText(temp);\r
        }\r
+       m_sLogMessage = m_cLogMessage.GetText();\r
+       if (!m_ProjectProperties.sMessage.IsEmpty())\r
+       {\r
+               CString sBugID = m_ProjectProperties.FindBugID(m_sLogMessage);\r
+               if (!sBugID.IsEmpty())\r
+               {\r
+                       SetDlgItemText(IDC_BUGID, sBugID);\r
+               }\r
+       }\r
 \r
        m_cLogMessage.SetFocus();\r
 \r
+       SysFreeString(parameters);\r
+       SysFreeString(commonRoot);\r
+       SafeArrayDestroy(pathList);\r
+       SysFreeString(originalMessage);\r
        SysFreeString(temp);\r
-#endif\r
+\r
 }\r
 \r
 LRESULT CCommitDlg::OnGitStatusListCtrlCheckChanged(WPARAM, LPARAM)\r
@@ -1577,3 +1630,8 @@ void CCommitDlg::OnBnClickedWholeProject()
            SetWindowText(m_sWindowTitle + _T(" - ") + commonDir.GetWinPathString());\r
 \r
 }\r
+\r
+void CCommitDlg::OnStnClickedBugidlabel()\r
+{\r
+       // TODO: Add your control notification handler code here\r
+}\r
index 9b2741a..b8f13a1 100644 (file)
@@ -28,7 +28,7 @@
 #include "PathWatcher.h"\r
 #include "BugTraqAssociations.h"\r
 #include "Tooltip.h"\r
-//#include "..\IBugTraqProvider\IBugTraqProvider_h.h"\r
+#include "..\IBugTraqProvider\IBugTraqProvider_h.h"\r
 #include "Git.h"\r
 \r
 #include <regex>\r
@@ -110,7 +110,7 @@ public:
        BOOL                            m_bCommitAmend;\r
        INT_PTR                         m_itemsCount;\r
        bool                            m_bSelectFilesForCommit;\r
-//     CComPtr<IBugTraqProvider> m_BugTraqProvider;\r
+       CComPtr<IBugTraqProvider> m_BugTraqProvider;\r
        CString                         m_NoAmendStr;\r
        CString                         m_AmendStr;\r
 \r
@@ -138,11 +138,12 @@ private:
        CRect                           m_LogMsgOrigRect;\r
        CPathWatcher            m_pathwatcher;\r
 \r
-//     CBugTraqAssociation m_bugtraq_association;\r
+       CBugTraqAssociation m_bugtraq_association;\r
 \r
 public:\r
        afx_msg void OnBnClickedSignOff();\r
        afx_msg void OnStnClickedCommitlabel();\r
        afx_msg void OnBnClickedCommitAmend();\r
     afx_msg void OnBnClickedWholeProject();\r
+       afx_msg void OnStnClickedBugidlabel();\r
 };\r
index c395a38..4c3e4dc 100644 (file)
@@ -101,6 +101,7 @@ BOOL CSetBugTraqAdv::OnInitDialog()
        AddAnchor(IDC_BUGTRAQPROVIDERCOMBO, TOP_LEFT, TOP_RIGHT);\r
        AddAnchor(IDC_BUGTRAQPARAMETERSLABEL, TOP_LEFT, TOP_RIGHT);\r
        AddAnchor(IDC_BUGTRAQPARAMETERS, TOP_LEFT, TOP_RIGHT);\r
+       AddAnchor(IDC_OPTIONS, TOP_RIGHT);\r
        AddAnchor(IDOK, BOTTOM_RIGHT);\r
        AddAnchor(IDCANCEL, BOTTOM_RIGHT);\r
        AddAnchor(IDHELP, BOTTOM_RIGHT);\r
index bf74599..e50ec80 100644 (file)
Binary files a/src/TortoiseProc/resource.h and b/src/TortoiseProc/resource.h differ
index fede37a..e9666cf 100644 (file)
@@ -86,6 +86,14 @@ bool CBugTraqAssociations::FindProvider(const CTGitPathList &pathList, CBugTraqA
        return FindProviderForPathList(pathList, assoc);\r
 }\r
 \r
+bool CBugTraqAssociations::FindProvider(const CString &path, CBugTraqAssociation *assoc) const\r
+{\r
+\r
+       CTGitPath gitpath;\r
+       gitpath.SetFromUnknown(path);\r
+       return FindProviderForPath(gitpath,assoc);\r
+\r
+}\r
 bool CBugTraqAssociations::FindProviderForPathList(const CTGitPathList &pathList, CBugTraqAssociation *assoc) const\r
 {\r
        for (int i = 0; i < pathList.GetCount(); ++i)\r
index 54b5210..44836a6 100644 (file)
@@ -68,6 +68,7 @@ public:
        void RemoveByPath(const CTGitPath &path);\r
 \r
        bool FindProvider(const CTGitPathList &pathList, CBugTraqAssociation *assoc) const;\r
+       bool FindProvider(const CString &path, CBugTraqAssociation *assoc) const;\r
 \r
        typedef inner_t::const_iterator const_iterator;\r
        const_iterator begin() const { return m_inner.begin(); }\r