OSDN Git Service

diff command basic finished
authorFrank Li <lznuaa@gmail.com>
Wed, 17 Dec 2008 14:53:09 +0000 (22:53 +0800)
committerFrank Li <lznuaa@gmail.com>
Wed, 17 Dec 2008 14:53:09 +0000 (22:53 +0800)
13 files changed:
src/Git/Git.h
src/Git/GitAdminDir.cpp
src/Git/GitAdminDir.h
src/Git/TGitPath.cpp
src/TortoiseGitSetup/UIFragment.wxi
src/TortoiseProc/Commands/Command.cpp
src/TortoiseProc/Commands/Command.h
src/TortoiseProc/Commands/DiffCommand.cpp
src/TortoiseProc/Commands/PrevDiffCommand.cpp
src/TortoiseProc/GitDiff.cpp
src/TortoiseProc/TortoiseProc.cpp
src/TortoiseProc/TortoiseProc.vcproj
src/TortoiseProc/TortoiseProc.vcproj.FSL.B20596.user

index 57652c3..56f8d66 100644 (file)
@@ -1,7 +1,7 @@
 #pragma once\r
 #include "GitRev.h"\r
 #include "GitStatus.h"\r
-\r
+#include "GitAdminDir.h"\r
 enum\r
 {\r
        GIT_SUCCESS=0,\r
@@ -11,6 +11,8 @@ enum
 };\r
 class CGit\r
 {\r
+private:\r
+       GitAdminDir m_GitDir;\r
 public:\r
 \r
        CGit(void);\r
@@ -20,7 +22,13 @@ public:
        CString GetUserName(void);\r
        CString GetUserEmail(void);\r
        CString GetCurrentBranch(void);\r
+\r
+       bool SetCurrentDir(CString path)\r
+       {\r
+               return m_GitDir.HasAdminDir(path,&m_CurrentDir);\r
+       }\r
        CString m_CurrentDir;\r
+       \r
        int GetLog(CString& logOut);\r
        git_revnum_t GetHash(CString &friendname);\r
        \r
index 3ed2137..d050f77 100644 (file)
@@ -73,13 +73,25 @@ bool GitAdminDir::IsAdminDirName(const CString& name) const
 #endif\r
        return name == ".git";\r
 }\r
+CString GitAdminDir::GetGitTopDir(const CString& path) \r
+{\r
+       CString str;\r
+       str=_T("");\r
+       HasAdminDir(path,!!PathIsDirectory(path),&str);\r
+       return str;\r
+}\r
 \r
 bool GitAdminDir::HasAdminDir(const CString& path) const\r
 {\r
        return HasAdminDir(path, !!PathIsDirectory(path));\r
 }\r
 \r
-bool GitAdminDir::HasAdminDir(const CString& path, bool bDir) const\r
+bool GitAdminDir::HasAdminDir(const CString& path,CString *ProjectTopDir) const\r
+{\r
+       return HasAdminDir(path, !!PathIsDirectory(path),ProjectTopDir);\r
+}\r
+\r
+bool GitAdminDir::HasAdminDir(const CString& path, bool bDir,CString *ProjectTopDir) const\r
 {\r
        if (path.IsEmpty())\r
                return false;\r
@@ -93,7 +105,11 @@ bool GitAdminDir::HasAdminDir(const CString& path, bool bDir) const
        do\r
        {\r
                if(PathFileExists(sDirName + _T("\\.git")))\r
+               {\r
+                       if(ProjectTopDir)\r
+                               *ProjectTopDir=sDirName;\r
                        return true;\r
+               }\r
                sDirName = sDirName.Left(sDirName.ReverseFind('\\'));\r
 \r
        }while(sDirName.ReverseFind('\\')>0);\r
index 8620acb..00778a8 100644 (file)
@@ -27,7 +27,9 @@ public:
        /// Returns true if the path (file or folder) has an admin directory \r
        /// associated, i.e. if the path is in a working copy.\r
        bool HasAdminDir(const CString& path) const;\r
-       bool HasAdminDir(const CString& path, bool bDir) const;\r
+       bool HasAdminDir(const CString& path,CString * ProjectTopDir=NULL) const;\r
+       bool HasAdminDir(const CString& path, bool bDir,CString * ProjectTopDir=NULL) const;\r
+       CString GetGitTopDir(const CString& path);\r
        \r
        /// Returns true if the admin dir name is set to "_svn".\r
        bool IsVSNETHackActive() const {return m_bVSNETHack;}\r
index 10a7ed7..7417a4f 100644 (file)
@@ -148,7 +148,12 @@ void CTGitPath::SetFromUnknown(const CString& sPath)
 {\r
        Reset();\r
        // Just set whichever path we think is most likely to be used\r
-       SetFwdslashPath(sPath);\r
+//     GitAdminDir admin;\r
+//     CString p;\r
+//     if(admin.HasAdminDir(sPath,&p))\r
+//             SetFwdslashPath(sPath.Right(sPath.GetLength()-p.GetLength()));\r
+//     else\r
+               SetFwdslashPath(sPath);\r
 }\r
 \r
 LPCTSTR CTGitPath::GetWinPath() const\r
index b6f7775..49008e9 100644 (file)
           <Publish Event="NewDialog" Value="LicenseAgreementDlg">1</Publish>\r
         </Control>\r
         <Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="[ButtonText_Next]">\r
-          <Publish Event="SetTargetPath" Value="TARGETDIR">1</Publish>\r
-          <Publish Event="NewDialog" Value="VerifyReadyDlg">1</Publish>\r
+          <Publish Event="SetTargetPath" Value="MSYSGITDIR">1</Publish>\r
+          <Publish Event="NewDialog" Value="CustomizeDlg">1</Publish>\r
         </Control>\r
         <Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="[ButtonText_Cancel]">\r
           <Publish Event="SpawnDialog" Value="CancelPopup">1</Publish>\r
         </Control>\r
         <Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="[ButtonText_Next]">\r
           <Publish Event="SpawnWaitDialog" Value="WaitForCostingPopup">CostingComplete = 1</Publish>\r
-          <Publish Event="NewDialog" Value="MSysGitLocation">"Yes"</Publish>\r
+          <Publish Event="NewDialog" Value="CustomizeDlg">"Yes"</Publish>\r
           <Publish Property="InstallMode" Value="Custom">1</Publish>\r
           <Condition Action="disable"><![CDATA[IAgree <> "Yes"]]></Condition>\r
           <Condition Action="enable">IAgree = "Yes"</Condition>\r
index 72b9e7c..8ae4b06 100644 (file)
@@ -25,6 +25,8 @@
 \r
 #include "CreateRepositoryCommand.h"\r
 #include "CloneCommand.h"\r
+#include "PrevDiffCommand.h"\r
+#include "DiffCommand.h"\r
 \r
 #if 0\r
 #include "AddCommand.h"\r
@@ -39,7 +41,7 @@
 #include "CreatePatchCommand.h"\r
 \r
 #include "DelUnversionedCommand.h"\r
-#include "DiffCommand.h"\r
+\r
 #include "DropCopyAddCommand.h"\r
 #include "DropCopyCommand.h"\r
 #include "DropExportCommand.h"\r
@@ -54,7 +56,7 @@
 #include "MergeAllCommand.h"\r
 #include "PasteCopyCommand.h"\r
 #include "PasteMoveCommand.h"\r
-#include "PrevDiffCommand.h"\r
+\r
 #include "PropertiesCommand.h"\r
 #include "RebuildIconCacheCommand.h"\r
 #include "RelocateCommand.h"\r
@@ -219,6 +221,10 @@ Command * CommandServer::GetCommand(const CString& sCmd)
                return new CreateRepositoryCommand;\r
        case cmdClone:\r
                return new CloneCommand;\r
+       case cmdPrevDiff:\r
+               return new PrevDiffCommand;\r
+       case cmdDiff:\r
+               return new DiffCommand;\r
 #if 0\r
        case cmdAdd:\r
                return new AddCommand;\r
@@ -241,8 +247,7 @@ Command * CommandServer::GetCommand(const CString& sCmd)
                return new CreatePatchCommand;\r
        case cmdDelUnversioned:\r
                return new DelUnversionedCommand;\r
-       case cmdDiff:\r
-               return new DiffCommand;\r
+\r
        case cmdDropCopy:\r
                return new DropCopyCommand;\r
        case cmdDropCopyAdd:\r
@@ -313,6 +318,7 @@ Command * CommandServer::GetCommand(const CString& sCmd)
                return new UrlDiffCommand;\r
 #endif\r
        default:\r
+               CMessageBox::Show(hWndExplorer, _T("Have not implemented"), _T("TortoiseGit"), MB_ICONERROR);\r
                return new AboutCommand;\r
        }\r
 }\r
index 7d52b04..183e3ae 100644 (file)
@@ -37,7 +37,14 @@ public:
        virtual bool                    Execute() = 0;\r
 \r
        void                                    SetParser(const CCmdLineParser& p) {parser = p;}\r
-       void                                    SetPaths(const CTGitPathList& plist, const CTGitPath path) {pathList = plist; cmdLinePath = path;}\r
+       void                                    SetPaths(const CTGitPathList& plist, const CTGitPath path) \r
+                                                       {       \r
+                                                               CString WinPath=path.GetWinPath();\r
+                                                               if(WinPath.Left(g_Git.m_CurrentDir.GetLength())==g_Git.m_CurrentDir)\r
+                                                                       cmdLinePath.SetFromWin( WinPath.Right(WinPath.GetLength()-g_Git.m_CurrentDir.GetLength()-1));\r
+\r
+                                                               pathList = plist; \r
+                                                       }\r
        void                                    SetExplorerHwnd(HWND hWnd) {hwndExplorer = hWnd;}\r
 protected:\r
        CCmdLineParser                  parser;\r
index a39d576..db596f9 100644 (file)
@@ -20,9 +20,9 @@
 #include "DiffCommand.h"\r
 #include "PathUtils.h"\r
 #include "AppUtils.h"\r
-#include "ChangedDlg.h"\r
-#include "SVNDiff.h"\r
-#include "SVNStatus.h"\r
+//#include "ChangedDlg.h"\r
+#include "GitDiff.h"\r
+#include "GitStatus.h"\r
 \r
 bool DiffCommand::Execute()\r
 {\r
@@ -34,31 +34,31 @@ bool DiffCommand::Execute()
        {\r
                if (cmdLinePath.IsDirectory())\r
                {\r
-                       CChangedDlg dlg;\r
-                       dlg.m_pathList = CTSVNPathList(cmdLinePath);\r
-                       dlg.DoModal();\r
-                       bRet = true;\r
+                       //CChangedDlg dlg;\r
+                       //dlg.m_pathList = CTSVNPathList(cmdLinePath);\r
+                       //dlg.DoModal();\r
+                       //bRet = true;\r
                }\r
                else\r
                {\r
-                       SVNDiff diff(NULL, hwndExplorer);\r
-                       diff.SetAlternativeTool(bAlternativeTool);\r
+                       CGitDiff diff;\r
+                       //diff.SetAlternativeTool(bAlternativeTool);\r
                        if ( parser.HasKey(_T("startrev")) && parser.HasKey(_T("endrev")) )\r
                        {\r
-                               SVNRev StartRevision = SVNRev(parser.GetLongVal(_T("startrev")));\r
-                               SVNRev EndRevision = SVNRev(parser.GetLongVal(_T("endrev")));\r
-                               bRet = diff.ShowCompare(cmdLinePath, StartRevision, cmdLinePath, EndRevision, SVNRev(), false, bBlame);\r
+                               //SVNRev StartRevision = SVNRev(parser.GetLongVal(_T("startrev")));\r
+                               //SVNRev EndRevision = SVNRev(parser.GetLongVal(_T("endrev")));\r
+                               //bRet = diff.ShowCompare(cmdLinePath, StartRevision, cmdLinePath, EndRevision, SVNRev(), false, bBlame);\r
                        }\r
                        else\r
                        {\r
-                               svn_revnum_t baseRev = 0;\r
-                               bRet = diff.DiffFileAgainstBase(cmdLinePath, baseRev);\r
+                               //svn_revnum_t baseRev = 0;\r
+                               bRet = diff.Diff(&cmdLinePath,git_revnum_t(_T("HEAD")),git_revnum_t(GIT_REV_ZERO));\r
                        }\r
                }\r
        } \r
        else\r
                bRet = CAppUtils::StartExtDiff(\r
-                       CTSVNPath(path2), cmdLinePath, CString(), CString(),\r
+                       path2, cmdLinePath.GetWinPathString(), CString(), CString(),\r
                        CAppUtils::DiffFlags().AlternativeTool(bAlternativeTool));\r
        return bRet;\r
 }
\ No newline at end of file
index 5584eea..d5a3c11 100644 (file)
@@ -18,9 +18,8 @@
 //\r
 #include "StdAfx.h"\r
 #include "PrevDiffCommand.h"\r
-#include "ChangedDlg.h"\r
-#include "SVNDiff.h"\r
-#include "SVNStatus.h"\r
+#include "GitDiff.h"\r
+#include "GitStatus.h"\r
 #include "MessageBox.h"\r
 \r
 bool PrevDiffCommand::Execute()\r
@@ -29,32 +28,33 @@ bool PrevDiffCommand::Execute()
        bool bAlternativeTool = !!parser.HasKey(_T("alternative"));\r
        if (cmdLinePath.IsDirectory())\r
        {\r
-               CChangedDlg dlg;\r
-               dlg.m_pathList = CTSVNPathList(cmdLinePath);\r
-               dlg.DoModal();\r
-               bRet = true;\r
+//             CChangedDlg dlg;\r
+//             dlg.m_pathList = CTSVNPathList(cmdLinePath);\r
+//             dlg.DoModal();\r
+//             bRet = true;\r
        }\r
        else\r
        {\r
-               SVNDiff diff;\r
-               diff.SetAlternativeTool(bAlternativeTool);\r
-               SVNStatus st;\r
+               CGitDiff diff;\r
+//             diff.SetAlternativeTool(bAlternativeTool);\r
+               GitStatus st;\r
                st.GetStatus(cmdLinePath);\r
-               if (st.status && st.status->entry && st.status->entry->cmt_rev)\r
+\r
+               if (1)\r
                {\r
-                       SVNDiff diff(NULL, hWndExplorer);\r
-                       bRet = diff.ShowCompare(cmdLinePath, SVNRev::REV_WC, cmdLinePath, st.status->entry->cmt_rev - 1, st.status->entry->cmt_rev);\r
+                       CGitDiff diff;\r
+                       bRet = diff.Diff(&cmdLinePath, git_revnum_t(_T("HEAD")), git_revnum_t(_T("HEAD~1")), false);\r
                }\r
                else\r
                {\r
-                       if (st.GetLastErrorMsg().IsEmpty())\r
+                       //if (st.GetLastErrorMsg().IsEmpty())\r
                        {\r
                                CMessageBox::Show(hWndExplorer, IDS_ERR_NOPREVREVISION, IDS_APPNAME, MB_ICONERROR);\r
                        }\r
-                       else\r
-                       {\r
-                               CMessageBox::Show(hWndExplorer, IDS_ERR_NOSTATUS, IDS_APPNAME, MB_ICONERROR);\r
-                       }\r
+                       //else\r
+                       //{\r
+                       //      CMessageBox::Show(hWndExplorer, IDS_ERR_NOSTATUS, IDS_APPNAME, MB_ICONERROR);\r
+                       //s}\r
                }\r
        }\r
        return bRet;\r
index 9dde4bd..b1cc743 100644 (file)
@@ -28,7 +28,7 @@ int CGitDiff::Diff(CTGitPath * pPath, git_revnum_t & rev1, git_revnum_t & rev2,
                                g_Git.RunLogFile(cmd,file1);\r
        }else\r
        {\r
-               file1=pPath->GetWinPathString();\r
+               file1=g_Git.m_CurrentDir+_T("\\")+pPath->GetWinPathString();\r
        }\r
 \r
        CString file2;\r
@@ -44,7 +44,7 @@ int CGitDiff::Diff(CTGitPath * pPath, git_revnum_t & rev1, git_revnum_t & rev2,
                g_Git.RunLogFile(cmd,file2);\r
        }else\r
        {\r
-               file2=pPath->GetWinPathString();\r
+               file2=g_Git.m_CurrentDir+_T("\\")+pPath->GetWinPathString();\r
        }\r
        \r
        CAppUtils::DiffFlags flags;\r
index 8dd922d..b242118 100644 (file)
@@ -114,7 +114,7 @@ BOOL CTortoiseProcApp::InitInstance()
        CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));\r
        CMFCButton::EnableWindowsTheming();\r
        //set the resource dll for the required language\r
-       CRegDWORD loc = CRegDWORD(_T("Software\\TortoiseSVN\\LanguageID"), 1033);\r
+       CRegDWORD loc = CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);\r
        long langId = loc;\r
        CString langDll;\r
        CStringA langpath = CStringA(CPathUtils::GetAppParentDirectory());\r
@@ -162,7 +162,7 @@ BOOL CTortoiseProcApp::InitInstance()
        sHelppath.Replace(_T("tortoiseproc.chm"), _T("TortoiseSVN_en.chm"));\r
        free((void*)m_pszHelpFilePath);\r
        m_pszHelpFilePath=_tcsdup(sHelppath);\r
-       sHelppath = CPathUtils::GetAppParentDirectory() + _T("Languages\\TortoiseSVN_en.chm");\r
+       sHelppath = CPathUtils::GetAppParentDirectory() + _T("Languages\\TortoiseGit_en.chm");\r
        do\r
        {\r
                CString sLang = _T("_");\r
@@ -220,13 +220,13 @@ BOOL CTortoiseProcApp::InitInstance()
        AfxEnableControlContainer();\r
        AfxInitRichEdit2();\r
        CWinAppEx::InitInstance();\r
-       SetRegistryKey(_T("TortoiseSVN"));\r
+       SetRegistryKey(_T("TortoiseGit"));\r
 \r
        CCmdLineParser parser(AfxGetApp()->m_lpCmdLine);\r
 \r
        // if HKCU\Software\TortoiseSVN\Debug is not 0, show our command line\r
        // in a message box\r
-       if (CRegDWORD(_T("Software\\TortoiseSVN\\Debug"), FALSE)==TRUE)\r
+       if (CRegDWORD(_T("Software\\TortoiseGit\\Debug"), FALSE)==TRUE)\r
                AfxMessageBox(AfxGetApp()->m_lpCmdLine, MB_OK | MB_ICONINFORMATION);\r
 \r
        if ( parser.HasKey(_T("path")) && parser.HasKey(_T("pathfile")))\r
@@ -241,6 +241,7 @@ BOOL CTortoiseProcApp::InitInstance()
        {\r
 \r
                CString sPathfileArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("pathfile")));\r
+\r
                cmdLinePath.SetFromUnknown(sPathfileArgument);\r
                if (pathList.LoadFromFile(cmdLinePath)==false)\r
                        return FALSE;           // no path specified!\r
@@ -371,8 +372,18 @@ BOOL CTortoiseProcApp::InitInstance()
        if (cmd)\r
        {\r
                cmd->SetExplorerHwnd(hWndExplorer);\r
+               \r
+               if(!g_Git.SetCurrentDir(cmdLinePath.GetWinPathString()))\r
+               {\r
+                       int i=0;\r
+                       for(i=0;i<pathList.GetCount();i++)\r
+                               if(g_Git.SetCurrentDir(pathList[i].GetWinPath()))\r
+                                       break;\r
+               }\r
+\r
                cmd->SetParser(parser);\r
                cmd->SetPaths(pathList, cmdLinePath);\r
+\r
                retSuccess = cmd->Execute();\r
                delete cmd;\r
        }\r
index f10b617..1a108a7 100644 (file)
                                        >\r
                                </File>\r
                        </Filter>\r
+                       <Filter\r
+                               Name="PrevDiff"\r
+                               >\r
+                               <File\r
+                                       RelativePath=".\Commands\PrevDiffCommand.cpp"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath=".\Commands\PrevDiffCommand.h"\r
+                                       >\r
+                               </File>\r
+                       </Filter>\r
+                       <Filter\r
+                               Name="Diff"\r
+                               >\r
+                               <File\r
+                                       RelativePath=".\Commands\DiffCommand.cpp"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath=".\Commands\DiffCommand.h"\r
+                                       >\r
+                               </File>\r
+                       </Filter>\r
                </Filter>\r
                <Filter\r
                        Name="Utility Dialogs"\r
index ee3cfa3..d6f4a59 100644 (file)
@@ -11,7 +11,7 @@
                        <DebugSettings\r
                                Command="$(TargetPath)"\r
                                WorkingDirectory="D:\Profiles\b20596\tortoisegit"\r
-                               CommandArguments="/command:commit /path:&quot;D:\test2&quot;"\r
+                               CommandArguments="/command:diff /path:&quot;D:\Profiles\b20596\qgit4\src\cache.cpp&quot;"\r
                                Attach="false"\r
                                DebuggerType="3"\r
                                Remote="1"\r