OSDN Git Service

UDIFF working Okay
authorFrank Li <lznuaa@gmail.com>
Sat, 22 Nov 2008 09:21:06 +0000 (17:21 +0800)
committerFrank Li <lznuaa@gmail.com>
Sat, 22 Nov 2008 09:21:06 +0000 (17:21 +0800)
Git/Git.cpp
Git/Git.h
TortoiseProc/AppUtils.cpp
TortoiseProc/AppUtils.h
TortoiseProc/LogDlg.cpp
TortoiseShell/TortoiseShell.sln
TortoiseShell/TortoiseShell.suo
TortoiseUDiff/TortoiseUDiff.vcproj

index 765a8a4..60b79b2 100644 (file)
@@ -129,3 +129,73 @@ int CGit::GetLog(CString& logOut)
        Run(cmd,&logOut);\r
        return 0;\r
 }\r
+\r
+#define BUFSIZE 512\r
+CString GetTempFile()\r
+{\r
+       TCHAR lpPathBuffer[BUFSIZE];\r
+       DWORD dwRetVal;\r
+    DWORD dwBufSize=BUFSIZE;\r
+       TCHAR szTempName[BUFSIZE];  \r
+       UINT uRetVal;\r
+\r
+       dwRetVal = GetTempPath(dwBufSize,     // length of the buffer\r
+                           lpPathBuffer); // buffer for path \r
+    if (dwRetVal > dwBufSize || (dwRetVal == 0))\r
+    {\r
+        return _T("");\r
+    }\r
+        // Create a temporary file. \r
+    uRetVal = GetTempFileName(lpPathBuffer, // directory for tmp files\r
+                              TEXT("Patch"),  // temp file name prefix \r
+                              0,            // create unique name \r
+                              szTempName);  // buffer for name \r
+\r
+\r
+    if (uRetVal == 0)\r
+    {\r
+        return _T("");\r
+    }\r
+\r
+       return CString(szTempName);\r
+\r
+}\r
+\r
+int CGit::RunLogFile(CString cmd,CString &filename)\r
+{\r
+       HANDLE hRead, hWrite;\r
+\r
+       STARTUPINFO si;\r
+       PROCESS_INFORMATION pi;\r
+       si.cb=sizeof(STARTUPINFO);\r
+       GetStartupInfo(&si);\r
+\r
+       SECURITY_ATTRIBUTES   psa={sizeof(psa),NULL,TRUE};;   \r
+       psa.bInheritHandle=TRUE;   \r
+    \r
+       HANDLE   houtfile=CreateFile(filename,GENERIC_WRITE,FILE_SHARE_READ   |   FILE_SHARE_WRITE,   \r
+                       &psa,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);   \r
+\r
+\r
+       si.wShowWindow=SW_HIDE;\r
+       si.dwFlags=STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;\r
+       si.hStdOutput   =   houtfile; \r
+       \r
+       if(!CreateProcess(NULL,(LPWSTR)cmd.GetString(), NULL,NULL,TRUE,NULL,NULL,(LPWSTR)m_CurrentDir.GetString(),&si,&pi))\r
+       {\r
+               LPVOID lpMsgBuf;\r
+               FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,\r
+                       NULL,GetLastError(),MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),\r
+                       (LPTSTR)&lpMsgBuf,\r
+                       0,NULL);\r
+               return GIT_ERROR_CREATE_PROCESS;\r
+       }\r
+       \r
+       WaitForSingleObject(pi.hProcess,INFINITE);   \r
+       \r
+       CloseHandle(pi.hThread);\r
+       CloseHandle(pi.hProcess);\r
+       CloseHandle(houtfile);\r
+       return GIT_SUCCESS;\r
+       return 0;\r
+}\r
index 22a4fb5..915b668 100644 (file)
--- a/Git/Git.h
+++ b/Git/Git.h
@@ -13,11 +13,15 @@ public:
        CGit(void);\r
        ~CGit(void);\r
        int Run(CString cmd, CString* output);\r
+       int RunLogFile(CString cmd, CString &filename);\r
        CString GetUserName(void);\r
        CString GetUserEmail(void);\r
        CString GetCurrentBranch(void);\r
        CString m_CurrentDir;\r
        int GetLog(CString& logOut);\r
+       \r
 };\r
 \r
+extern CString GetTempFile();\r
+\r
 extern CGit g_Git;
\ No newline at end of file
index 7192d47..e4088e3 100644 (file)
@@ -376,7 +376,7 @@ BOOL CAppUtils::StartExtDiffProps(const CTGitPath& file1, const CTGitPath& file2
        return TRUE;\r
 }\r
 \r
-BOOL CAppUtils::StartUnifiedDiffViewer(const CTGitPath& patchfile, const CString& title, BOOL bWait)\r
+BOOL CAppUtils::StartUnifiedDiffViewer(const CString& patchfile, const CString& title, BOOL bWait)\r
 {\r
        CString viewer;\r
        CRegString v = CRegString(_T("Software\\TortoiseGit\\DiffViewer"));\r
@@ -395,12 +395,12 @@ BOOL CAppUtils::StartUnifiedDiffViewer(const CTGitPath& patchfile, const CString
        if (viewer.Find(_T("%1"))>=0)\r
        {\r
                if (viewer.Find(_T("\"%1\"")) >= 0)\r
-                       viewer.Replace(_T("%1"), patchfile.GetWinPathString());\r
+                       viewer.Replace(_T("%1"), patchfile);\r
                else\r
-                       viewer.Replace(_T("%1"), _T("\"") + patchfile.GetWinPathString() + _T("\""));\r
+                       viewer.Replace(_T("%1"), _T("\"") + patchfile + _T("\""));\r
        }\r
        else\r
-               viewer += _T(" \"") + patchfile.GetWinPathString() + _T("\"");\r
+               viewer += _T(" \"") + patchfile + _T("\"");\r
        if (viewer.Find(_T("%title")) >= 0)\r
        {\r
                viewer.Replace(_T("%title"), title);\r
index 5ff0690..c244bef 100644 (file)
@@ -69,7 +69,7 @@ public:
         * Starts the external unified diff viewer (the app associated with *.diff or *.patch files).\r
         * If no app is associated with those file types, the default text editor is used.\r
         */\r
-       static BOOL StartUnifiedDiffViewer(const CTGitPath& patchfile, const CString& title, BOOL bWait = FALSE);\r
+       static BOOL StartUnifiedDiffViewer(const CString& patchfile, const CString& title, BOOL bWait = FALSE);\r
 \r
        /**\r
         * Starts the external diff application\r
index 553d5a9..5f5f657 100644 (file)
@@ -3994,27 +3994,25 @@ void CLogDlg::ShowContextMenuForRevisions(CWnd* /*pWnd*/, CPoint point)
                {\r
                        case ID_GNUDIFF1:\r
                        {\r
-//                             if (PromptShown())\r
-//                             {\r
-//                                     GitDiff diff(this, this->m_hWnd, true);\r
-//                                     diff.SetHEADPeg(m_LogRevision);\r
-//                                     diff.ShowUnifiedDiff(m_path, revPrevious, m_path, revSelected);\r
-//                             }\r
-//                             else\r
-//                                     CAppUtils::StartShowUnifiedDiff(m_hWnd, m_path, revPrevious, m_path, revSelected, GitRev(), m_LogRevision);\r
+                               CString tempfile=GetTempFile();\r
+                               CString cmd;\r
+                               GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));\r
+                               cmd.Format(_T("git.cmd diff-tree -r -p --stat %s"),r1->m_CommitHash);\r
+                               g_Git.RunLogFile(cmd,tempfile);\r
+                               CAppUtils::StartUnifiedDiffViewer(tempfile,r1->m_CommitHash.Left(6)+_T(":")+r1->m_Subject);\r
                        }\r
                        break;\r
 \r
                        case ID_GNUDIFF2:\r
                        {\r
-//                             if (PromptShown())\r
-//                             {\r
-//                                     GitDiff diff(this, this->m_hWnd, true);\r
-//                                     diff.SetHEADPeg(m_LogRevision);\r
-//                                     diff.ShowUnifiedDiff(m_path, revSelected2, m_path, revSelected);\r
-//                             }\r
-//                             else\r
-//                                     CAppUtils::StartShowUnifiedDiff(m_hWnd, m_path, revSelected2, m_path, revSelected, GitRev(), m_LogRevision);\r
+                               CString tempfile=GetTempFile();\r
+                               CString cmd;\r
+                               GitRev * r1 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(FirstSelect));\r
+                               GitRev * r2 = reinterpret_cast<GitRev*>(m_arShownList.GetAt(LastSelect));\r
+                               cmd.Format(_T("git.cmd diff-tree -r -p --stat %s %s"),r1->m_CommitHash,r2->m_CommitHash);\r
+                               g_Git.RunLogFile(cmd,tempfile);\r
+                               CAppUtils::StartUnifiedDiffViewer(tempfile,r1->m_CommitHash.Left(6)+_T(":")+r2->m_CommitHash.Left(6));\r
+\r
                        }\r
                        break;\r
 \r
index 95b3037..c24dd34 100644 (file)
@@ -22,6 +22,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SciLexer", "..\ext\scintill
 EndProject\r
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hunspell", "..\ext\hunspell\hunspell.vcproj", "{12E5B4AE-D7EF-4A57-A22D-6F9F9D8CE1FB}"\r
 EndProject\r
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TortoiseUDiff", "..\TortoiseUDiff\TortoiseUDiff.vcproj", "{BC5A5F3B-E41A-4C56-B16F-263D2C6D6475}"\r
+EndProject\r
 Global\r
        GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
                Debug|Win32 = Debug|Win32\r
@@ -56,6 +58,10 @@ Global
                {12E5B4AE-D7EF-4A57-A22D-6F9F9D8CE1FB}.Debug|Win32.Build.0 = Debug|Win32\r
                {12E5B4AE-D7EF-4A57-A22D-6F9F9D8CE1FB}.Release|Win32.ActiveCfg = Release|Win32\r
                {12E5B4AE-D7EF-4A57-A22D-6F9F9D8CE1FB}.Release|Win32.Build.0 = Release|Win32\r
+               {BC5A5F3B-E41A-4C56-B16F-263D2C6D6475}.Debug|Win32.ActiveCfg = Debug|Win32\r
+               {BC5A5F3B-E41A-4C56-B16F-263D2C6D6475}.Debug|Win32.Build.0 = Debug|Win32\r
+               {BC5A5F3B-E41A-4C56-B16F-263D2C6D6475}.Release|Win32.ActiveCfg = Release|Win32\r
+               {BC5A5F3B-E41A-4C56-B16F-263D2C6D6475}.Release|Win32.Build.0 = Release|Win32\r
        EndGlobalSection\r
        GlobalSection(SolutionProperties) = preSolution\r
                HideSolutionNode = FALSE\r
index a33f88d..b7b0198 100644 (file)
Binary files a/TortoiseShell/TortoiseShell.suo and b/TortoiseShell/TortoiseShell.suo differ
index 1cb4b64..40e322c 100644 (file)
@@ -21,8 +21,8 @@
        <Configurations>\r
                <Configuration\r
                        Name="Debug|Win32"\r
-                       OutputDirectory="..\..\bin\Debug\bin"\r
-                       IntermediateDirectory="..\..\obj\TortoiseUDiff\Debug"\r
+                       OutputDirectory="..\bin\Debug\bin"\r
+                       IntermediateDirectory="..\obj\TortoiseUDiff\Debug"\r
                        ConfigurationType="1"\r
                        CharacterSet="1"\r
                        >\r
@@ -44,7 +44,7 @@
                        <Tool\r
                                Name="VCCLCompilerTool"\r
                                Optimization="0"\r
-                               AdditionalIncludeDirectories="..\..\ext\scintilla\include;..\Utils;..\Utils\MiscUI"\r
+                               AdditionalIncludeDirectories="..\ext\scintilla\include;..\Utils;..\Utils\MiscUI"\r
                                PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"\r
                                MinimalRebuild="true"\r
                                BasicRuntimeChecks="3"\r
                        />\r
                </Configuration>\r
                <Configuration\r
-                       Name="Debug|x64"\r
-                       OutputDirectory="..\..\bin\Debug64\bin"\r
-                       IntermediateDirectory="..\..\obj\TortoiseUDiff\Debug64"\r
+                       Name="Release|Win32"\r
+                       OutputDirectory="..\..\bin\Release\bin"\r
+                       IntermediateDirectory="..\..\obj\TortoiseUDiff\Release"\r
                        ConfigurationType="1"\r
                        CharacterSet="1"\r
+                       WholeProgramOptimization="1"\r
                        >\r
                        <Tool\r
                                Name="VCPreBuildEventTool"\r
                        />\r
                        <Tool\r
                                Name="VCMIDLTool"\r
-                               TargetEnvironment="3"\r
                        />\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
-                               Optimization="0"\r
                                AdditionalIncludeDirectories="..\..\ext\scintilla\include;..\Utils;..\Utils\MiscUI"\r
-                               PreprocessorDefinitions="WIN64;_DEBUG;_WINDOWS"\r
-                               MinimalRebuild="true"\r
-                               BasicRuntimeChecks="3"\r
-                               RuntimeLibrary="3"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"\r
+                               RuntimeLibrary="2"\r
                                UsePrecompiledHeader="2"\r
                                WarningLevel="4"\r
                                DebugInformationFormat="3"\r
                        />\r
                        <Tool\r
                                Name="VCLinkerTool"\r
-                               LinkIncremental="2"\r
+                               LinkIncremental="1"\r
                                GenerateDebugInformation="true"\r
                                SubSystem="2"\r
+                               OptimizeReferences="2"\r
+                               EnableCOMDATFolding="2"\r
+                               OptimizeForWindows98="0"\r
                                RandomizedBaseAddress="1"\r
                                DataExecutionPrevention="0"\r
-                               TargetMachine="17"\r
+                               TargetMachine="1"\r
                        />\r
                        <Tool\r
                                Name="VCALinkTool"\r
                        />\r
                </Configuration>\r
                <Configuration\r
-                       Name="Release|Win32"\r
-                       OutputDirectory="..\..\bin\Release\bin"\r
-                       IntermediateDirectory="..\..\obj\TortoiseUDiff\Release"\r
+                       Name="Debug|x64"\r
+                       OutputDirectory="..\..\bin\Debug64\bin"\r
+                       IntermediateDirectory="..\..\obj\TortoiseUDiff\Debug64"\r
                        ConfigurationType="1"\r
                        CharacterSet="1"\r
-                       WholeProgramOptimization="1"\r
                        >\r
                        <Tool\r
                                Name="VCPreBuildEventTool"\r
                        />\r
                        <Tool\r
                                Name="VCMIDLTool"\r
+                               TargetEnvironment="3"\r
                        />\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
                                AdditionalIncludeDirectories="..\..\ext\scintilla\include;..\Utils;..\Utils\MiscUI"\r
-                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"\r
-                               RuntimeLibrary="2"\r
+                               PreprocessorDefinitions="WIN64;_DEBUG;_WINDOWS"\r
+                               MinimalRebuild="true"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="3"\r
                                UsePrecompiledHeader="2"\r
                                WarningLevel="4"\r
                                DebugInformationFormat="3"\r
                        />\r
                        <Tool\r
                                Name="VCLinkerTool"\r
-                               LinkIncremental="1"\r
+                               LinkIncremental="2"\r
                                GenerateDebugInformation="true"\r
                                SubSystem="2"\r
-                               OptimizeReferences="2"\r
-                               EnableCOMDATFolding="2"\r
-                               OptimizeForWindows98="0"\r
                                RandomizedBaseAddress="1"\r
                                DataExecutionPrevention="0"\r
-                               TargetMachine="1"\r
+                               TargetMachine="17"\r
                        />\r
                        <Tool\r
                                Name="VCALinkTool"\r
                                        />\r
                                </FileConfiguration>\r
                                <FileConfiguration\r
-                                       Name="Debug|x64"\r
+                                       Name="Release|Win32"\r
                                        >\r
                                        <Tool\r
                                                Name="VCCLCompilerTool"\r
                                        />\r
                                </FileConfiguration>\r
                                <FileConfiguration\r
-                                       Name="Release|Win32"\r
+                                       Name="Debug|x64"\r
                                        >\r
                                        <Tool\r
                                                Name="VCCLCompilerTool"\r