Can specify specific paths of submodules to update
authorSup Yut Sum <ch3cooli@gmail.com>
Sun, 10 Feb 2013 13:55:38 +0000 (10 21:55 +0800)
committerSup Yut Sum <ch3cooli@gmail.com>
Sun, 10 Feb 2013 13:55:38 +0000 (10 21:55 +0800)
Signed-off-by: Sup Yut Sum <ch3cooli@gmail.com>
doc/images/en/SubmoduleUpdate.png
src/Changelog.txt
src/Resources/TortoiseProcENG.rc
src/TortoiseProc/Commands/SubmoduleCommand.cpp
src/TortoiseProc/SubmoduleUpdateDlg.cpp
src/TortoiseProc/SubmoduleUpdateDlg.h
src/TortoiseProc/resource.h

dissimilarity index 99%
index 27d130b..204da52 100644 (file)
Binary files a/doc/images/en/SubmoduleUpdate.png and b/doc/images/en/SubmoduleUpdate.png differ
index 8be3a5c..292a01a 100644 (file)
@@ -8,6 +8,7 @@ Released: unreleased
  * Revision Graph can save as graphviz dot language (*.gv)\r
  * Support merge strategies except octopus\r
  * Fixed issue #1597: Reduce chance of committing old submodule revision on cherry-pick / rebase conflicts\r
+ * Can specify specific paths of submodules to update\r
 \r
 = Release 1.8.1.0 =\r
 Released: 2013-02-07\r
index bf67c1c..195b0d3 100644 (file)
@@ -1682,22 +1682,24 @@ BEGIN
     PUSHBUTTON      "Help",IDHELP,204,130,50,14\r
 END\r
 \r
-IDD_SUBMODULE_UPDATE DIALOGEX 0, 0, 322, 87\r
+IDD_SUBMODULE_UPDATE DIALOGEX 0, 0, 322, 147\r
 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU\r
 CAPTION "Submodule Update"\r
 FONT 8, "MS Shell Dlg", 400, 0, 0x1\r
 BEGIN\r
-    GROUPBOX        "Submodule Update Options",IDC_GROUP_INFO,7,7,305,54\r
+    LTEXT           "Path:",IDC_STATIC,15,7,42,8\r
+    LISTBOX         IDC_LIST_PATH,61,4,250,60,LBS_SORT | LBS_MULTIPLESEL | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP\r
+    GROUPBOX        "Submodule Update Options",IDC_GROUP_INFO,7,67,305,54\r
     CONTROL         "&Initialize submodules (--init)",IDC_CHECK_SUBMODULE_INIT,\r
-                    "Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,17,140,13\r
-    CONTROL         "&Recursive",IDC_CHECK_SUBMODULE_RECURSIVE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,31,140,13\r
-    CONTROL         "&Force",IDC_FORCE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,44,140,13\r
-    CONTROL         "&No fetch",IDC_CHECK_SUBMODULE_NOFETCH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,165,17,140,13\r
-    CONTROL         "&Merge",IDC_CHECK_SUBMODULE_MERGE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,165,31,140,13\r
-    CONTROL         "Re&base",IDC_CHECK_SUBMODULE_REBASE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,165,44,140,13\r
-    DEFPUSHBUTTON   "OK",IDOK,149,65,50,14\r
-    PUSHBUTTON      "Cancel",IDCANCEL,205,65,50,14\r
-    PUSHBUTTON      "Help",IDHELP,262,65,50,14,WS_DISABLED\r
+                    "Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,77,140,13\r
+    CONTROL         "&Recursive",IDC_CHECK_SUBMODULE_RECURSIVE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,91,140,13\r
+    CONTROL         "&Force",IDC_FORCE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,104,140,13\r
+    CONTROL         "&No fetch",IDC_CHECK_SUBMODULE_NOFETCH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,165,77,140,13\r
+    CONTROL         "&Merge",IDC_CHECK_SUBMODULE_MERGE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,165,91,140,13\r
+    CONTROL         "Re&base",IDC_CHECK_SUBMODULE_REBASE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,165,104,140,13\r
+    DEFPUSHBUTTON   "OK",IDOK,149,125,50,14\r
+    PUSHBUTTON      "Cancel",IDCANCEL,205,125,50,14\r
+    PUSHBUTTON      "Help",IDHELP,262,125,50,14,WS_DISABLED\r
 END\r
 \r
 IDD_DIALOG_BROWSE_REFS DIALOGEX 0, 0, 465, 255\r
@@ -2532,7 +2534,7 @@ BEGIN
         RIGHTMARGIN, 312\r
         VERTGUIDE, 15\r
         TOPMARGIN, 7\r
-        BOTTOMMARGIN, 79\r
+        BOTTOMMARGIN, 139\r
     END\r
 \r
     IDD_DIALOG_BROWSE_REFS, DIALOG\r
index e8e8a4d..21adc28 100644 (file)
@@ -86,7 +86,19 @@ bool SubmoduleUpdateCommand::Execute()
                return false;\r
        }\r
 \r
+       STRING_VECTOR pathFilterList;\r
+       for (size_t i = 0; i < orgPathList.GetCount(); i++)\r
+       {\r
+               if (orgPathList[i].IsDirectory())\r
+               {\r
+                       CString path = ((CTGitPath &)orgPathList[i]).GetSubPath(CTGitPath(super)).GetGitPathString();\r
+                       if (!path.IsEmpty())\r
+                               pathFilterList.push_back(path);\r
+               }\r
+       }\r
+\r
        CSubmoduleUpdateDlg submoduleUpdateDlg;\r
+       submoduleUpdateDlg.m_PathFilterList = pathFilterList;\r
        if (submoduleUpdateDlg.DoModal() != IDOK)\r
                return false;\r
 \r
@@ -108,14 +120,11 @@ bool SubmoduleUpdateCommand::Execute()
        if (submoduleUpdateDlg.m_bRebase)\r
                params += _T(" --rebase");\r
 \r
-       for (int i = 0; i < this->orgPathList.GetCount(); ++i)\r
+       for (size_t i = 0; i < submoduleUpdateDlg.m_PathList.size(); ++i)\r
        {\r
-               if (orgPathList[i].IsDirectory())\r
-               {\r
-                       CString str;\r
-                       str.Format(_T("git.exe submodule update%s \"%s\""), params, ((CTGitPath &)orgPathList[i]).GetSubPath(CTGitPath(super)).GetGitPathString());\r
-                       progress.m_GitCmdList.push_back(str);\r
-               }\r
+               CString str;\r
+               str.Format(_T("git.exe submodule update%s \"%s\""), params, submoduleUpdateDlg.m_PathList[i]);\r
+               progress.m_GitCmdList.push_back(str);\r
        }\r
 \r
        progress.DoModal();\r
index 9e930c7..d3f6a75 100644 (file)
@@ -21,6 +21,9 @@
 #include "TortoiseProc.h"\r
 #include "SubmoduleUpdateDlg.h"\r
 #include "AppUtils.h"\r
+#include "git2.h"\r
+#include "UnicodeUtils.h"\r
+#include <Shlwapi.h>\r
 \r
 IMPLEMENT_DYNAMIC(CSubmoduleUpdateDlg, CStandAloneDialog)\r
 \r
@@ -42,6 +45,7 @@ CSubmoduleUpdateDlg::~CSubmoduleUpdateDlg()
 void CSubmoduleUpdateDlg::DoDataExchange(CDataExchange* pDX)\r
 {\r
        CStandAloneDialog::DoDataExchange(pDX);\r
+       DDX_Control(pDX, IDC_LIST_PATH, m_PathListBox);\r
        DDX_Check(pDX, IDC_CHECK_SUBMODULE_INIT, m_bInit);\r
        DDX_Check(pDX, IDC_CHECK_SUBMODULE_RECURSIVE, m_bRecursive);\r
        DDX_Check(pDX, IDC_FORCE, m_bForce);\r
@@ -54,8 +58,50 @@ void CSubmoduleUpdateDlg::DoDataExchange(CDataExchange* pDX)
 BEGIN_MESSAGE_MAP(CSubmoduleUpdateDlg, CStandAloneDialog)\r
        ON_BN_CLICKED(IDOK, &CSubmoduleUpdateDlg::OnBnClickedOk)\r
        ON_BN_CLICKED(IDHELP, &CSubmoduleUpdateDlg::OnBnClickedHelp)\r
+       ON_LBN_SELCHANGE(IDC_LIST_PATH, &CSubmoduleUpdateDlg::OnLbnSelchangeListPath)\r
 END_MESSAGE_MAP()\r
 \r
+static int SubmoduleCallback(git_submodule *sm, const char * /*name*/, void *payload)\r
+{\r
+       STRING_VECTOR *list = *(STRING_VECTOR **)payload;\r
+       STRING_VECTOR *prefixList = *((STRING_VECTOR **)payload + 1);\r
+       CString path = CUnicodeUtils::GetUnicode(git_submodule_path(sm));\r
+       if (prefixList->empty())\r
+       {\r
+               list->push_back(path);\r
+       }\r
+       else\r
+       {\r
+               for (size_t i = 0; i < prefixList->size(); ++i)\r
+               {\r
+                       CString prefix = prefixList->at(i) + _T("/");\r
+                       if (path.Left(prefix.GetLength()) == prefix)\r
+                               list->push_back(path);\r
+               }\r
+       }\r
+       return 0;\r
+}\r
+\r
+static void GetSubmodulePathList(STRING_VECTOR &list, STRING_VECTOR &prefixList)\r
+{\r
+       git_repository *repo;\r
+       if (git_repository_open(&repo, CUnicodeUtils::GetUTF8(g_Git.m_CurrentDir)))\r
+       {\r
+               MessageBox(NULL, g_Git.GetLibGit2LastErr(_T("Could not open repository.")), _T("TortoiseGit"), MB_ICONERROR);\r
+               return;\r
+       }\r
+\r
+       STRING_VECTOR *listParams[] = { &list, &prefixList };\r
+       if (git_submodule_foreach(repo, SubmoduleCallback, &listParams))\r
+       {\r
+               MessageBox(NULL, g_Git.GetLibGit2LastErr(_T("Could not get submodule list.")), _T("TortoiseGit"), MB_ICONERROR);\r
+               return;\r
+       }\r
+\r
+       git_repository_free(repo);\r
+       std::sort(list.begin(), list.end());\r
+}\r
+\r
 BOOL CSubmoduleUpdateDlg::OnInitDialog()\r
 {\r
        CStandAloneDialog::OnInitDialog();\r
@@ -71,6 +117,36 @@ BOOL CSubmoduleUpdateDlg::OnInitDialog()
        AdjustControlSize(IDC_CHECK_SUBMODULE_MERGE);\r
        AdjustControlSize(IDC_CHECK_SUBMODULE_REBASE);\r
 \r
+       CString WorkingDir = g_Git.m_CurrentDir;\r
+       WorkingDir.Replace(_T(':'), _T('_'));\r
+\r
+       m_regPath = CRegString(CString(_T("Software\\TortoiseGit\\History\\SubmoduleUpdatePath\\") + WorkingDir));\r
+       CString path = m_regPath;\r
+       STRING_VECTOR list;\r
+       GetSubmodulePathList(list, m_PathFilterList);\r
+       STRING_VECTOR selected;\r
+       int pos = 0;\r
+       while (pos >= 0)\r
+       {\r
+               CString part = path.Tokenize(_T("|"), pos);\r
+               if (!part.IsEmpty())\r
+                       selected.push_back(part);\r
+       }\r
+       for (size_t i = 0; i < list.size(); ++i)\r
+       {\r
+               m_PathListBox.AddString(list[i]);\r
+               if (selected.size() == 0)\r
+                       m_PathListBox.SetSel((int)i);\r
+               else\r
+               {\r
+                       for (int j = 0; j < selected.size(); ++j)\r
+                       {\r
+                               if (selected[j] == list[i])\r
+                                       m_PathListBox.SetSel((int)i);\r
+                       }\r
+               }\r
+       }\r
+\r
        UpdateData(FALSE);\r
 \r
        return TRUE;\r
@@ -79,6 +155,21 @@ BOOL CSubmoduleUpdateDlg::OnInitDialog()
 void CSubmoduleUpdateDlg::OnBnClickedOk()\r
 {\r
        CStandAloneDialog::UpdateData(TRUE);\r
+       m_PathList.clear();\r
+       CString selected;\r
+       for (int i = 0; i < m_PathListBox.GetCount(); ++i)\r
+       {\r
+               if (m_PathListBox.GetSel(i))\r
+               {\r
+                       if (!selected.IsEmpty())\r
+                               selected.Append(_T("|"));\r
+                       CString text;\r
+                       m_PathListBox.GetText(i, text);\r
+                       m_PathList.push_back(text);\r
+                       selected.Append(text);\r
+               }\r
+       }\r
+       m_regPath = selected;\r
 \r
        CStandAloneDialog::OnOK();\r
 }\r
@@ -87,3 +178,8 @@ void CSubmoduleUpdateDlg::OnBnClickedHelp()
 {\r
        OnHelp();\r
 }\r
+\r
+void CSubmoduleUpdateDlg::OnLbnSelchangeListPath()\r
+{\r
+       GetDlgItem(IDOK)->EnableWindow(m_PathListBox.GetSelCount() > 0 ? TRUE : FALSE);\r
+}\r
index cbc3d87..afbe5ad 100644 (file)
@@ -20,6 +20,8 @@
 #pragma once\r
 \r
 #include "StandAloneDlg.h"\r
+#include "registry.h"\r
+#include "HistoryCombo.h"\r
 \r
 class CSubmoduleUpdateDlg : public CStandAloneDialog\r
 {\r
@@ -40,6 +42,7 @@ protected:
 \r
        afx_msg void OnBnClickedOk();\r
        afx_msg void OnBnClickedHelp();\r
+       afx_msg void OnLbnSelchangeListPath();\r
 \r
 public:\r
        BOOL m_bInit;\r
@@ -48,4 +51,10 @@ public:
        BOOL m_bNoFetch;\r
        BOOL m_bMerge;\r
        BOOL m_bRebase;\r
+       STRING_VECTOR m_PathFilterList;\r
+       STRING_VECTOR m_PathList;\r
+\r
+protected:\r
+       CListBox        m_PathListBox;\r
+       CRegString              m_regPath;\r
 };\r
index a6ae7ed..78cf0a8 100644 (file)
 #define IDC_COMBO_MERGESTRATEGY         1745\r
 #define IDC_COMBO_STRATEGYOPTION        1746\r
 #define IDC_EDIT_STRATEGYPARAM          1747\r
+#define IDC_LIST_PATH                   1748\r
 #define IDS_DLGTITLE_ADD_DIFF_TOOL      1750\r
 #define IDS_DLGTITLE_ADD_MERGE_TOOL     1751\r
 #define IDS_DLGTITLE_EDIT_DIFF_TOOL     1752\r
 #ifndef APSTUDIO_READONLY_SYMBOLS\r
 #define _APS_NEXT_RESOURCE_VALUE        345\r
 #define _APS_NEXT_COMMAND_VALUE         32860\r
-#define _APS_NEXT_CONTROL_VALUE         1748\r
+#define _APS_NEXT_CONTROL_VALUE         1749\r
 #define _APS_NEXT_SYMED_VALUE           201\r
 #endif\r
 #endif\r