OSDN Git Service

Add Git submodule update and fix ProgressDlg show Okay when command still running.
authorFrank Li <lznuaa@gmail.com>
Fri, 20 Mar 2009 10:09:44 +0000 (18:09 +0800)
committerFrank Li <lznuaa@gmail.com>
Fri, 20 Mar 2009 10:40:36 +0000 (18:40 +0800)
Signed-off-by: Frank Li <lznuaa@gmail.com>
src/Git/GitAdminDir.cpp
src/Git/GitAdminDir.h
src/Git/TGitPath.cpp
src/Git/TGitPath.h
src/TortoiseProc/Commands/SubmoduleCommand.cpp
src/TortoiseProc/ProgressDlg.cpp
src/TortoiseProc/ProgressDlg.h
src/TortoiseShell/ContextMenu.cpp

index f05763b..44556ea 100644 (file)
@@ -65,6 +65,25 @@ bool GitAdminDir::Close()
        return true;\r
 }\r
 \r
+CString GitAdminDir::GetSuperProjectRoot(const CString& path) \r
+{\r
+       CString projectroot=path;\r
+               \r
+       do\r
+       {\r
+               if(PathFileExists(projectroot + _T("\\.gitmodules")))\r
+               {\r
+                       return projectroot;\r
+               }               \r
+               \r
+               projectroot = projectroot.Left(projectroot.ReverseFind('\\'));\r
+\r
+       }while(projectroot.ReverseFind('\\')>0);\r
+\r
+       return _T("");\r
+\r
+}\r
+\r
 bool GitAdminDir::IsAdminDirName(const CString& name) const\r
 {\r
 #if 0\r
index bc1e02c..53adcef 100644 (file)
@@ -29,6 +29,8 @@ public:
        bool HasAdminDir(const CString& path) const;\r
        bool HasAdminDir(const CString& path,CString * ProjectTopDir) const;\r
        bool HasAdminDir(const CString& path, bool bDir,CString * ProjectTopDir=NULL) const;\r
+       CString GetSuperProjectRoot(const CString& path);\r
+\r
        CString GetGitTopDir(const CString& path);\r
        \r
        /// Returns true if the admin dir name is set to "_svn".\r
index dbd0dc0..859069c 100644 (file)
@@ -428,6 +428,17 @@ void CTGitPath::UpdateAttributes() const
        m_bExistsKnown = true;\r
 }\r
 \r
+CTGitPath CTGitPath::GetSubPath(CTGitPath &root)\r
+{\r
+       CTGitPath path;\r
+       \r
+       if(GetWinPathString().Left(root.GetWinPathString().GetLength()) == root.GetWinPathString())\r
+       {\r
+               CString str=GetWinPathString();\r
+               path.SetFromWin(str.Right(str.GetLength()-root.GetWinPathString().GetLength()-1));\r
+       }\r
+       return path;\r
+}\r
 \r
 void CTGitPath::EnsureBackslashPathSet() const\r
 {\r
@@ -1911,3 +1922,4 @@ int CTGitPathList::GetAction()
 {\r
        return m_Action;\r
 }\r
+\r
index 22bfb09..783e3e7 100644 (file)
@@ -97,6 +97,9 @@ public:
         * Returns true if the path points to a directory\r
         */\r
        bool IsDirectory() const;\r
+\r
+       CTGitPath GetSubPath(CTGitPath &root);\r
+\r
        /**\r
         * Returns the directory. If the path points to a directory, then the path\r
         * is returned unchanged. If the path points to a file, the path to the \r
index c10c75c..eb5efad 100644 (file)
@@ -44,6 +44,9 @@ bool SubmoduleAddCommand::Execute()
                if(dlg.m_bBranch)\r
                        branch.Format(_T(" -b %s "), dlg.m_strBranch);\r
 \r
+               dlg.m_strPath.Replace(_T('\\'),_T('/'));\r
+               dlg.m_strRepos.Replace(_T('\\'),_T('/'));\r
+\r
                cmd.Format(_T("git.exe submodule add %s -- \"%s\"  \"%s\""),\r
                                                branch,\r
                                                dlg.m_strRepos, dlg.m_strPath);\r
@@ -60,7 +63,31 @@ bool SubmoduleAddCommand::Execute()
 bool SubmoduleUpdateCommand::Execute()\r
 {\r
        bool bRet = false;\r
+       CProgressDlg progress;\r
+       CString bkpath=parser.GetVal(_T("bkpath"));\r
 \r
+       CString super=g_GitAdminDir.GetSuperProjectRoot( bkpath );\r
+       if(super.IsEmpty())\r
+       {\r
+               CMessageBox::Show(NULL,_T("Can't found Super project"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
+               //change current project root to super project\r
+               return false;\r
+       }\r
 \r
-       return bRet;\r
+       g_Git.m_CurrentDir=super;\r
+       \r
+       progress.m_Title.Format(_T("Submodule update - %s"),super);\r
+\r
+       //progress.m_GitCmd.Format(_T("git.exe submodule update --init "));\r
+\r
+       CString str;\r
+       for(int i=0;i<this->orgPathList.GetCount();i++)\r
+       {\r
+               str.Format(_T("git.exe submodule update --init \"%s\""),((CTGitPath &)orgPathList[i]).GetSubPath(CTGitPath(super)).GetGitPathString());\r
+               progress.m_GitCmdList.push_back(str);\r
+       }\r
+\r
+       progress.DoModal();\r
+\r
+       return !progress.m_GitStatus;\r
 }\r
index 3ec55ba..e1a86dd 100644 (file)
@@ -56,7 +56,7 @@ BOOL CProgressDlg::OnInitDialog()
        {\r
                InitialText = m_PreText + _T("\r\n");\r
        }\r
-       if (m_bShowCommand)\r
+       if (m_bShowCommand && (!m_GitCmd.IsEmpty() ))\r
        {\r
                InitialText += m_GitCmd+_T("\r\n\r\n");\r
        }\r
@@ -73,6 +73,9 @@ BOOL CProgressDlg::OnInitDialog()
                m_pThread->m_bAutoDelete = FALSE;\r
                m_pThread->ResumeThread();\r
        }\r
+\r
+       if(!m_Title.IsEmpty())\r
+               this->SetWindowText(m_Title);\r
        return TRUE;\r
 }\r
 \r
@@ -94,25 +97,44 @@ UINT CProgressDlg::ProgressThread()
        else\r
                pfilename=&m_LogFile;\r
 \r
-       g_Git.RunAsync(this->m_GitCmd,&pi, &hRead,pfilename);\r
+       m_GitCmdList.push_back(m_GitCmd);\r
+\r
+       m_GitStatus =0;\r
 \r
-       DWORD readnumber;\r
-       char buffer[2];\r
-       CString output;\r
-       while(ReadFile(hRead,buffer,1,&readnumber,NULL))\r
+       for(int i=0;i<m_GitCmdList.size();i++)\r
        {\r
-               buffer[readnumber]=0;\r
-               this->PostMessage(MSG_PROGRESSDLG_UPDATE_UI,MSG_PROGRESSDLG_END,(TCHAR)buffer[0]);\r
-       }\r
+               if(m_GitCmdList[i].IsEmpty())\r
+                       continue;\r
 \r
-       CloseHandle(pi.hThread);\r
+               if (m_bShowCommand && m_GitCmdList[i]!= m_GitCmd)\r
+               {\r
+                       CString str;\r
+                       str+= m_GitCmdList[i]+_T("\r\n\r\n");\r
+                       for(int j=0;j<str.GetLength();j++)\r
+                               this->PostMessage(MSG_PROGRESSDLG_UPDATE_UI,MSG_PROGRESSDLG_RUN,str[j]);\r
+               }\r
 \r
-       WaitForSingleObject(pi.hProcess, INFINITE);\r
-       m_GitStatus =0;\r
+               g_Git.RunAsync(this->m_GitCmdList[i],&pi, &hRead,pfilename);\r
 \r
-       if(!GetExitCodeProcess(pi.hProcess,&m_GitStatus))\r
-       {\r
-               return GIT_ERROR_GET_EXIT_CODE;\r
+               DWORD readnumber;\r
+               char buffer[2];\r
+               CString output;\r
+               while(ReadFile(hRead,buffer,1,&readnumber,NULL))\r
+               {\r
+                       buffer[readnumber]=0;\r
+                       this->PostMessage(MSG_PROGRESSDLG_UPDATE_UI,MSG_PROGRESSDLG_RUN,(TCHAR)buffer[0]);\r
+               }\r
+       \r
+               CloseHandle(pi.hThread);\r
+\r
+               WaitForSingleObject(pi.hProcess, INFINITE);\r
+               \r
+               DWORD status=0;\r
+               if(!GetExitCodeProcess(pi.hProcess,&status))\r
+               {\r
+                       return GIT_ERROR_GET_EXIT_CODE;\r
+               }\r
+               m_GitStatus |= status;\r
        }\r
 \r
        CloseHandle(pi.hProcess);\r
index f646018..ffedb50 100644 (file)
@@ -5,6 +5,7 @@
 #define MSG_PROGRESSDLG_UPDATE_UI      (WM_USER+121)\r
 // CProgressDlg dialog\r
 #define MSG_PROGRESSDLG_START 0\r
+#define MSG_PROGRESSDLG_RUN   50\r
 #define MSG_PROGRESSDLG_END   110\r
 \r
 class CProgressDlg : public CResizableStandAloneDialog\r
@@ -18,11 +19,14 @@ public:
 // Dialog Data\r
        enum { IDD = IDD_GITPROGRESS };\r
        CString m_GitCmd;\r
+       std::vector<CString> m_GitCmdList;\r
+\r
        CString m_LogFile;\r
 \r
        CProgressCtrl m_Progress;\r
        \r
        CEdit             m_Log;\r
+       CString m_Title;\r
        CAnimateCtrl  m_Animate;\r
        CStatic           m_CurrentWork;\r
        CWinThread*                             m_pThread;      \r
index d6e4136..9a2148f 100644 (file)
@@ -1488,7 +1488,8 @@ STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)
                                svnCmd += tempfile;\r
                                svnCmd += _T("\"");\r
                                svnCmd += _T(" /deletepathfile");\r
-                               svnCmd += _T(" /rev");\r
+                               svnCmd += _T(" /bkpath:");\r
+                               svnCmd += folder_;\r
                                break;\r
                        case ShellMenuCommit:\r
                                tempfile = WriteFileListToTempFile();\r