OSDN Git Service

Enable IBugTraqProvide CheckCommit and OnCommitFinished
authorFrank Li <lznuaa@gmail.com>
Thu, 15 Oct 2009 13:59:14 +0000 (21:59 +0800)
committerFrank Li <lznuaa@gmail.com>
Thu, 15 Oct 2009 14:14:54 +0000 (22:14 +0800)
Signed-off-by: Frank Li <lznuaa@gmail.com>
src/Git/Git.cpp
src/Git/Git.h
src/TortoiseProc/CommitDlg.cpp
src/Utils/COMError.cpp [new file with mode: 0644]
src/Utils/COMError.h [new file with mode: 0644]
src/Utils/Utils.vcproj

index a105f19..ec7b852 100644 (file)
@@ -1270,4 +1270,21 @@ bool CGit::IsFastForward(CString &from, CString &to)
        hash=hash.Left(40);\r
        \r
        return hash == base;\r
+}\r
+\r
+unsigned int CGit::Hash2int(CString &hash)\r
+{\r
+       int ret=0;\r
+       for(int i=0;i<8;i++)\r
+       {\r
+               ret =ret <<4;\r
+               if(hash[i]>=_T('a'))\r
+                       ret |= (hash[i]-_T('a')+10)&0xFF;\r
+               else if(hash[i]>=_T('A'))\r
+                       ret |= (hash[i]-_T('A')+10)&0xFF;\r
+               else\r
+                       ret |= (hash[i]-_T('0'))&0xFF;          \r
+               \r
+       }\r
+       return ret;\r
 }
\ No newline at end of file
index ba62ff1..0f9074d 100644 (file)
@@ -34,6 +34,7 @@ public:
        static BOOL CheckMsysGitDir();\r
        static CString ms_LastMsysGitDir;       // the last msysgitdir added to the path, blank if none\r
        static int m_LogEncode;\r
+       unsigned int Hash2int(CString &hash);\r
 //     static CString m_MsysGitPath;\r
        \r
        PROCESS_INFORMATION m_CurrentGitPi;\r
index ee5e999..101da5e 100644 (file)
@@ -36,6 +36,7 @@
 #include "ShellUpdater.h"\r
 #include "Commands/PushCommand.h"\r
 #include "PatchViewDlg.h"\r
+#include "COMError.h"\r
 \r
 #ifdef _DEBUG\r
 #define new DEBUG_NEW\r
@@ -358,6 +359,7 @@ void CCommitDlg::OnOK()
                        return;\r
        }\r
 \r
+       m_ListCtrl.WriteCheckedNamesToPathList(m_selectedPathList);\r
 #if 0\r
        CRegDWORD regUnversionedRecurse (_T("Software\\TortoiseGit\\UnversionedRecurse"), TRUE);\r
        if (!(DWORD)regUnversionedRecurse)\r
@@ -391,6 +393,44 @@ void CCommitDlg::OnOK()
        //std::set<CString> checkedLists;\r
        //std::set<CString> uncheckedLists;\r
 \r
+               // now let the bugtraq plugin check the commit message\r
+       CComPtr<IBugTraqProvider2> pProvider2 = NULL;\r
+       if (m_BugTraqProvider)\r
+       {\r
+               HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider2);\r
+               if (SUCCEEDED(hr))\r
+               {\r
+                       BSTR temp = NULL;\r
+                       CString common = g_Git.m_CurrentDir;\r
+                       BSTR repositoryRoot = common.AllocSysString();\r
+                       BSTR parameters = m_bugtraq_association.GetParameters().AllocSysString();\r
+                       BSTR commonRoot = SysAllocString(m_pathList.GetCommonRoot().GetDirectory().GetWinPath());\r
+                       BSTR commitMessage = m_sLogMessage.AllocSysString();\r
+                       SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0, m_selectedPathList.GetCount());\r
+\r
+                       for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)\r
+                               SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());\r
+\r
+                       if (FAILED(hr = pProvider2->CheckCommit(GetSafeHwnd(), parameters, repositoryRoot, commonRoot, pathList, commitMessage, &temp)))\r
+                       {\r
+                               COMError ce(hr);\r
+                               CString sErr;\r
+                               sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, m_bugtraq_association.GetProviderName(), ce.GetMessageAndDescription().c_str());\r
+                               CMessageBox::Show(m_hWnd, sErr, _T("TortoiseSVN"), MB_ICONERROR);\r
+                       }\r
+                       else\r
+                       {\r
+                               CString sError = temp;\r
+                               if (!sError.IsEmpty())\r
+                               {\r
+                                       CMessageBox::Show(m_hWnd, sError, _T("TortoiseSVN"), MB_ICONERROR);\r
+                                       return;\r
+                               }\r
+                               SysFreeString(temp);\r
+                       }\r
+               }\r
+       }\r
+\r
        //CString checkedfiles;\r
        //CString uncheckedfiles;\r
 \r
@@ -540,8 +580,49 @@ void CCommitDlg::OnOK()
                        //User pressed 'Push' button after successful commit.\r
                        m_bPushAfterCommit=true;\r
                }\r
-\r
+               \r
                CFile::Remove(tempfile);\r
+\r
+               if (m_BugTraqProvider && progress.m_GitStatus == 0)\r
+               {\r
+                       CComPtr<IBugTraqProvider2> pProvider = NULL;\r
+                       HRESULT hr = m_BugTraqProvider.QueryInterface(&pProvider);\r
+                       if (SUCCEEDED(hr))\r
+                       {\r
+                               BSTR commonRoot = SysAllocString(g_Git.m_CurrentDir);\r
+                               SAFEARRAY *pathList = SafeArrayCreateVector(VT_BSTR, 0,this->m_selectedPathList.GetCount());\r
+\r
+                               for (LONG index = 0; index < m_selectedPathList.GetCount(); ++index)\r
+                                       SafeArrayPutElement(pathList, &index, m_selectedPathList[index].GetGitPathString().AllocSysString());\r
+\r
+                               BSTR logMessage = m_sLogMessage.AllocSysString();\r
+\r
+                               CString hash=g_Git.GetHash(CString(_T("HEAD")));\r
+                               LONG version = g_Git.Hash2int(hash);\r
+\r
+                               BSTR temp = NULL;\r
+                               if (FAILED(hr = pProvider->OnCommitFinished(GetSafeHwnd(), \r
+                                       commonRoot,\r
+                                       pathList,\r
+                                       logMessage,\r
+                                       (LONG)version,\r
+                                       &temp)))\r
+                               {\r
+                                       CString sErr = temp;\r
+                                       if (!sErr.IsEmpty())\r
+                                               CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
+                                       else\r
+                                       {\r
+                                               COMError ce(hr);\r
+                                               sErr.Format(IDS_ERR_FAILEDISSUETRACKERCOM, ce.GetSource().c_str(), ce.GetMessageAndDescription().c_str());\r
+                                               CMessageBox::Show(NULL,(sErr),_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
+                                       }\r
+                               }\r
+\r
+                               SysFreeString(temp);\r
+                       }\r
+               }\r
+               \r
        }else\r
        {\r
                CMessageBox::Show(this->m_hWnd, IDS_ERROR_NOTHING_COMMIT, IDS_COMMIT_FINISH, MB_OK | MB_ICONINFORMATION);\r
@@ -646,7 +727,7 @@ void CCommitDlg::OnOK()
                //save only the files the user has checked into the temporary file\r
                m_ListCtrl.WriteCheckedNamesToPathList(m_pathList);\r
        }\r
-       m_ListCtrl.WriteCheckedNamesToPathList(m_selectedPathList);\r
+       \r
        // the item count is used in the progress dialog to show the overall commit\r
        // progress.\r
        // deleted items only send one notification event, all others send two\r
diff --git a/src/Utils/COMError.cpp b/src/Utils/COMError.cpp
new file mode 100644 (file)
index 0000000..f8c4b02
--- /dev/null
@@ -0,0 +1,60 @@
+// TortoiseSVN - a Windows shell extension for easy version control\r
+\r
+// Copyright (C) 2009 - TortoiseSVN\r
+\r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// as published by the Free Software Foundation; either version 2\r
+// of the License, or (at your option) any later version.\r
+\r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+// GNU General Public License for more details.\r
+\r
+// You should have received a copy of the GNU General Public License\r
+// along with this program; if not, write to the Free Software Foundation,\r
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
+//\r
+#include "StdAfx.h"\r
+#include "COMError.h"\r
+\r
+#pragma comment(lib, "Rpcrt4.lib")\r
+\r
+COMError::COMError(HRESULT hr)\r
+{\r
+       _com_error e(hr);\r
+       IErrorInfo *pIErrorInfo = NULL;\r
+       GetErrorInfo(0, &pIErrorInfo);\r
+\r
+       if (pIErrorInfo == NULL)\r
+       {\r
+               e = _com_error(hr);\r
+               message = e.ErrorMessage();\r
+       }\r
+       else\r
+       {\r
+               e = _com_error(hr, pIErrorInfo);\r
+               message = e.ErrorMessage();\r
+               IErrorInfo *ptrIErrorInfo = e.ErrorInfo();\r
+               if (ptrIErrorInfo != NULL)\r
+               {\r
+                       // IErrorInfo Interface located\r
+                       description = (WCHAR *)e.Description();\r
+                       source = (WCHAR *)e.Source();\r
+                       GUID tmpGuid = e.GUID();\r
+                       RPC_WSTR guidStr = NULL;\r
+                       // must link in Rpcrt4.lib for UuidToString\r
+                       UuidToString(&tmpGuid, &guidStr);\r
+                       uuid = (WCHAR*)guidStr;\r
+                       RpcStringFree(&guidStr);\r
+\r
+                       ptrIErrorInfo->Release();\r
+               }\r
+       }\r
+}\r
+\r
+COMError::~COMError()\r
+{\r
+\r
+}
\ No newline at end of file
diff --git a/src/Utils/COMError.h b/src/Utils/COMError.h
new file mode 100644 (file)
index 0000000..8041233
--- /dev/null
@@ -0,0 +1,38 @@
+// TortoiseSVN - a Windows shell extension for easy version control\r
+\r
+// Copyright (C) 2009 - TortoiseSVN\r
+\r
+// This program is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU General Public License\r
+// as published by the Free Software Foundation; either version 2\r
+// of the License, or (at your option) any later version.\r
+\r
+// This program is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+// GNU General Public License for more details.\r
+\r
+// You should have received a copy of the GNU General Public License\r
+// along with this program; if not, write to the Free Software Foundation,\r
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
+//\r
+#pragma once\r
+\r
+class COMError\r
+{\r
+public:\r
+       COMError(HRESULT hr);\r
+       virtual ~COMError();\r
+\r
+       std::wstring GetMessage() {return message;}\r
+       std::wstring GetDescription() {return description;}\r
+       std::wstring GetMessageAndDescription() {return message + _T("\n") + description;}\r
+       std::wstring GetSource() {return source;}\r
+       std::wstring GetUUID() {return uuid;}\r
+\r
+private:\r
+       std::wstring message;\r
+       std::wstring description;\r
+       std::wstring source;\r
+       std::wstring uuid;\r
+};\r
index 8ccb98e..886ce81 100644 (file)
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath=".\COMError.cpp"\r
+                               >\r
+                       </File>\r
+                       <File\r
                                RelativePath=".\CSmtp.cpp"\r
                                >\r
                                <FileConfiguration\r