OSDN Git Service

added 'conflict' status and fixed status detection for context menu
authorMyagi <snowcoder@gmail.com>
Mon, 2 Feb 2009 17:40:21 +0000 (18:40 +0100)
committerFrank Li <lznuaa@gmail.com>
Tue, 3 Feb 2009 03:31:43 +0000 (11:31 +0800)
ext/wingit/wingit.dll
ext/wingit/wingit.h
src/Git/GitStatus.cpp
src/Git/GitStatus.h
src/TortoiseShell/ContextMenu.cpp

index b9552ca..d29c333 100644 (file)
Binary files a/ext/wingit/wingit.dll and b/ext/wingit/wingit.dll differ
index 4693207..8794c3f 100644 (file)
@@ -13,7 +13,7 @@
 #ifndef _WINGIT_H_\r
 #define _WINGIT_H_\r
 \r
-#define WG_VERSION "0.1.6"\r
+#define WG_VERSION "0.1.7"\r
 \r
 \r
 #define DLLIMPORT __declspec(dllimport) __stdcall\r
@@ -56,6 +56,9 @@ enum WGFILESTATUS
 {\r
        WGFS_Normal,\r
        WGFS_Modified,\r
+       //WGFS_Staged,\r
+       //WGFS_Added,\r
+       WGFS_Conflicted,\r
        WGFS_Deleted,\r
 \r
        WGFS_Unknown = -1,\r
@@ -74,7 +77,6 @@ struct wgFile_s
 {\r
        const char *sFileName;                  // filename or directory relative to project root (using forward slashes)\r
        int nStatus;                                    // the WGFILESTATUS of the file\r
-       int nStage;                                             // the stage number of the file (0 if unstaged)\r
        int nFlags;                                             // a combination of WGFILEFLAGS\r
 \r
        const BYTE* sha1;                               // points to the BYTE[20] sha1 (NULL for directories, WGFF_Directory)\r
index 67ddc28..272d88f 100644 (file)
@@ -216,7 +216,7 @@ git_wc_status_kind GitStatus::GetAllStatus(const CTGitPath& path, git_depth_t de
 \r
        LPCSTR lpszSubPath = NULL;\r
        CStringA sSubPath;\r
-       CString s = path.GetDirectory().GetWinPathString();\r
+       CString s = path.GetWinPathString();\r
        if (s.GetLength() > sProjectRoot.GetLength())\r
        {\r
                sSubPath = CStringA(s.Right(s.GetLength() - sProjectRoot.GetLength() - 1/*otherwise it gets initial slash*/));\r
@@ -345,7 +345,7 @@ git_revnum_t GitStatus::GetStatus(const CTGitPath& path, bool update /* = false
 \r
        LPCSTR lpszSubPath = NULL;\r
        CStringA sSubPath;\r
-       CString s = path.GetDirectory().GetWinPathString();\r
+       CString s = path.GetWinPathString();\r
        if (s.GetLength() > sProjectRoot.GetLength())\r
        {\r
                sSubPath = CStringA(s.Right(s.GetLength() - sProjectRoot.GetLength() - 1/*otherwise it gets initial slash*/));\r
@@ -360,6 +360,7 @@ git_revnum_t GitStatus::GetStatus(const CTGitPath& path, bool update /* = false
 \r
        m_status.prop_status = m_status.text_status = git_wc_status_none;\r
 \r
+       // NOTE: currently wgEnumFiles will not enumerate file if it isn't versioned (so status will be git_wc_status_none)\r
        m_err = !wgEnumFiles(CStringA(sProjectRoot), lpszSubPath, nFlags, &getstatus, &m_status);\r
 \r
        /*m_err = git_client_status4 (&youngest,\r
@@ -378,7 +379,7 @@ git_revnum_t GitStatus::GetStatus(const CTGitPath& path, bool update /* = false
 \r
 \r
        // Error present if function is not under version control\r
-       if ((m_err != NULL) || /*(apr_hash_count(statushash) == 0)*/m_status.prop_status == git_wc_status_none)\r
+       if ((m_err != NULL) /*|| (apr_hash_count(statushash) == 0)*/)\r
        {\r
                status = NULL;\r
 //             return -2;      \r
index ea566e2..c482b75 100644 (file)
@@ -70,6 +70,9 @@ inline static git_wc_status_kind GitStatusFromWingit(int nStatus)
        {\r
        case WGFS_Normal: return git_wc_status_normal;\r
        case WGFS_Modified: return git_wc_status_modified;\r
+       //case WGFS_Staged: return git_wc_status_modified;\r
+       //case WGFS_Added: return git_wc_status_added;\r
+       case WGFS_Conflicted: return git_wc_status_conflicted;\r
        case WGFS_Deleted: return git_wc_status_deleted;\r
 \r
        case WGFS_Empty: return git_wc_status_unversioned;\r
index cc471cb..6e26662 100644 (file)
@@ -308,12 +308,12 @@ STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST pIDFolder,
                                                                        fetchedstatus = status;\r
                                                                        //if ((stat.status->entry)&&(stat.status->entry->lock_token))\r
                                                                        //      itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;\r
-                                                                       //if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))\r
-                                                                       //{\r
-                                                                       //      itemStates |= ITEMIS_FOLDER;\r
-                                                                       //      if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))\r
-                                                                       //              itemStates |= ITEMIS_FOLDERINGit;\r
-                                                                       //}\r
+                                                                       if ( askedpath.IsDirectory() )//if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))\r
+                                                                       {\r
+                                                                               itemStates |= ITEMIS_FOLDER;\r
+                                                                               if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))\r
+                                                                                       itemStates |= ITEMIS_FOLDERINSVN;\r
+                                                                       }\r
                                                                        //if ((stat.status->entry)&&(stat.status->entry->present_props))\r
                                                                        //{\r
                                                                        //      if (strstr(stat.status->entry->present_props, "svn:needs-lock"))\r
@@ -402,14 +402,15 @@ STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST pIDFolder,
                                                                                fetchedstatus = status;\r
                                                                                //if ((stat.status->entry)&&(stat.status->entry->lock_token))\r
                                                                                //      itemStates |= (stat.status->entry->lock_token[0] != 0) ? ITEMIS_LOCKED : 0;\r
-                                                                               //if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))\r
-                                                                               //{\r
-                                                                               //      itemStates |= ITEMIS_FOLDER;\r
-                                                                               //      if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))\r
-                                                                               //              itemStates |= ITEMIS_FOLDERINGit;\r
-                                                                               //}\r
-                                                                               //if ((stat.status->entry)&&(stat.status->entry->conflict_wrk))\r
-                                                                               //      itemStates |= ITEMIS_CONFLICTED;\r
+                                                                               if ( strpath.IsDirectory() )//if ((stat.status->entry)&&(stat.status->entry->kind == git_node_dir))\r
+                                                                               {\r
+                                                                                       itemStates |= ITEMIS_FOLDER;\r
+                                                                                       if ((status != git_wc_status_unversioned)&&(status != git_wc_status_ignored)&&(status != git_wc_status_none))\r
+                                                                                               itemStates |= ITEMIS_FOLDERINSVN;\r
+                                                                               }\r
+                                                                               // TODO: do we need to check that it's not a dir? does conflict options makes sense for dir in git?\r
+                                                                               if (status == git_wc_status_conflicted)//if ((stat.status->entry)&&(stat.status->entry->conflict_wrk))\r
+                                                                                       itemStates |= ITEMIS_CONFLICTED;\r
                                                                                //if ((stat.status->entry)&&(stat.status->entry->present_props))\r
                                                                                //{\r
                                                                                //      if (strstr(stat.status->entry->present_props, "svn:needs-lock"))\r
@@ -470,9 +471,8 @@ STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST pIDFolder,
                                        }\r
                                } // for (int i = 0; i < count; ++i)\r
                                ItemIDList child (GetPIDLItem (cida, 0), &parent);\r
-// ? was this disabled because the /wc option does not work safely with Git? or because the code below didn't compile before?\r
-//                             if (g_ShellCache.HasSVNAdminDir(child.toString().c_str(), FALSE))\r
-//                                     itemStates |= ITEMIS_INVERSIONEDFOLDER;\r
+                               if (g_ShellCache.HasSVNAdminDir(child.toString().c_str(), FALSE))\r
+                                       itemStates |= ITEMIS_INVERSIONEDFOLDER;\r
                                GlobalUnlock(medium.hGlobal);\r
 \r
                                // if the item is a versioned folder, check if there's a patch file\r
@@ -1064,10 +1064,12 @@ STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
        int menuIndex = 0;\r
        bool bAddSeparator = false;\r
        bool bMenuEntryAdded = false;\r
+       bool bMenuEmpty = true;\r
        // insert separator at start\r
        InsertMenu(hMenu, indexMenu++, MF_SEPARATOR|MF_BYPOSITION, 0, NULL); idCmd++;\r
        bool bShowIcons = !!DWORD(CRegStdWORD(_T("Software\\TortoiseGit\\ShowContextMenuIcons"), TRUE));\r
-       if (fullver <= 0x0500)\r
+       // ?? TortoiseSVN had this as (fullver <= 0x0500) this disabled icons in win2k, but icons work fine in win2k\r
+       if (fullver < 0x0500)\r
                bShowIcons = false;\r
        while (menuInfo[menuIndex].command != ShellMenuLastEntry)\r
        {\r
@@ -1077,7 +1079,8 @@ STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
                        // another 'normal' menu entry after we insert a separator.\r
                        // we simply set a flag here, indicating that before the next\r
                        // 'normal' menu entry, a separator should be added.\r
-                       bAddSeparator = true;\r
+                       if (!bMenuEmpty)\r
+                               bAddSeparator = true;\r
                }\r
                else\r
                {\r
@@ -1150,6 +1153,7 @@ STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
                                        {\r
                                                InsertIgnoreSubmenus(idCmd, idCmdFirst, hMenu, subMenu, indexMenu, indexSubMenu, topmenu, bShowIcons);\r
                                                bMenuEntryAdded = true;\r
+                                               bMenuEmpty = false;\r
                                        }\r
                                        else\r
                                        {\r
@@ -1171,7 +1175,10 @@ STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu,
                                                                                menuInfo[menuIndex].command,\r
                                                                                uFlags);\r
                                                if (!bIsTop)\r
+                                               {\r
                                                        bMenuEntryAdded = true;\r
+                                                       bMenuEmpty = false;\r
+                                               }\r
                                        }\r
                                }\r
                        }\r