Repository Browser: Allow to copy tree / blob hashes to clipboard
authorSup Yut Sum <ch3cooli@gmail.com>
Thu, 18 Apr 2013 15:17:30 +0000 (18 23:17 +0800)
committerSup Yut Sum <ch3cooli@gmail.com>
Thu, 18 Apr 2013 15:17:30 +0000 (18 23:17 +0800)
Signed-off-by: Sup Yut Sum <ch3cooli@gmail.com>
src/Changelog.txt
src/TortoiseProc/RepositoryBrowser.cpp
src/TortoiseProc/RepositoryBrowser.h

index 9f8ccc8..f8f6187 100644 (file)
@@ -8,6 +8,7 @@ Released: unreleased
  * TortoiseGitBlame: Allow to highlight lines by age of last modification\r
  * Fixed issue #1376: Daemon starting from Tortoise UI\r
  * Fixed issue #1737: Make a button to rename remote\r
+ * Repository Browser: Allow to copy tree / blob hashes to clipboard\r
 \r
 == Bug Fixes ==\r
  * Fixed issue #1729: crash when commit\r
index 37d8408..b444944 100644 (file)
@@ -321,9 +321,11 @@ int CRepositoryBrowser::ReadTreeRecursive(git_repository &repo, git_tree * tree,
                if (object == NULL)\r
                        continue;\r
 \r
+               const git_oid *oid = git_object_id(object);\r
                CShadowFilesTree * pNextTree = &treeroot->m_ShadowTree[base];\r
                pNextTree->m_sName = base;\r
                pNextTree->m_pParent = treeroot;\r
+               pNextTree->m_hash = CGitHash((char *)oid->id);\r
 \r
                if (mode & S_IFDIR)\r
                {\r
@@ -344,8 +346,6 @@ int CRepositoryBrowser::ReadTreeRecursive(git_repository &repo, git_tree * tree,
                }\r
                else\r
                {\r
-                       const git_oid * oid = git_object_id(object);\r
-\r
                        git_blob * blob;\r
                        git_blob_lookup(&blob, &repo, oid);\r
                        if (blob == NULL)\r
@@ -586,6 +586,7 @@ void CRepositoryBrowser::ShowContextMenu(CPoint point, TShadowFilesTreeList &sel
        bAddSeparator = false;\r
 \r
        popupMenu.AppendMenuIcon(eCmd_CopyPath, IDS_STATUSLIST_CONTEXT_COPY, IDI_COPYCLIP);\r
+       popupMenu.AppendMenuIcon(eCmd_CopyHash, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP);\r
 \r
        eCmd cmd = (eCmd)popupMenu.TrackPopupMenuEx(TPM_LEFTALIGN|TPM_RETURNCMD, point.x, point.y, this, 0);\r
        switch(cmd)\r
@@ -651,6 +652,11 @@ void CRepositoryBrowser::ShowContextMenu(CPoint point, TShadowFilesTreeList &sel
                        CStringUtils::WriteAsciiStringToClipboard(sClipboard);\r
                }\r
                break;\r
+       case eCmd_CopyHash:\r
+               {\r
+                       CopyHashToClipboard(selectedLeafs);\r
+               }\r
+               break;\r
        }\r
 }\r
 \r
@@ -1009,4 +1015,21 @@ bool CRepositoryBrowser::RevertItemToVersion(const CString &path)
        }\r
 \r
        return true;\r
+}\r
+\r
+void CRepositoryBrowser::CopyHashToClipboard(TShadowFilesTreeList &selectedLeafs)\r
+{\r
+       if (!selectedLeafs.empty())\r
+       {\r
+               CString sClipdata;\r
+               bool first = true;\r
+               for (int i = 0; i < selectedLeafs.size(); i++)\r
+               {\r
+                       if (!first)\r
+                               sClipdata += _T("\r\n");\r
+                       sClipdata += selectedLeafs[i]->m_hash;\r
+                       first = false;\r
+               }\r
+               CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd());\r
+       }\r
 }
\ No newline at end of file
index 13f31a8..2dbd0ca 100644 (file)
@@ -21,6 +21,7 @@
 \r
 #include <map>\r
 #include "StandAloneDlg.h"\r
+#include "GitHash.h"\r
 \r
 #define REPOBROWSER_CTRL_MIN_WIDTH     20\r
 \r
@@ -39,6 +40,7 @@ public:
        {}\r
 \r
        CString                         m_sName;\r
+       CGitHash                        m_hash;\r
        size_t                          m_iSize;\r
        bool                            m_bFolder;\r
 \r
@@ -85,6 +87,7 @@ public:
                eCmd_Revert,\r
                eCmd_SaveAs,\r
                eCmd_CopyPath,\r
+               eCmd_CopyHash,\r
        };\r
 \r
        enum eCol\r
@@ -164,4 +167,5 @@ private:
        afx_msg void                    OnCaptureChanged(CWnd *pWnd);\r
        afx_msg void                    OnLButtonDown(UINT nFlags, CPoint point);\r
        afx_msg void                    OnLButtonUp(UINT nFlags, CPoint point);\r
+       afx_msg void                    CopyHashToClipboard(TShadowFilesTreeList &selectedLeafs);\r
 };\r