From eafc360a331f7d6ebcef0af7fceedaab49cd1b81 Mon Sep 17 00:00:00 2001 From: Sup Yut Sum Date: Thu, 18 Apr 2013 23:17:30 +0800 Subject: [PATCH] Repository Browser: Allow to copy tree / blob hashes to clipboard Signed-off-by: Sup Yut Sum --- src/Changelog.txt | 1 + src/TortoiseProc/RepositoryBrowser.cpp | 27 +++++++++++++++++++++++++-- src/TortoiseProc/RepositoryBrowser.h | 4 ++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/Changelog.txt b/src/Changelog.txt index 9f8ccc8d2..f8f618736 100644 --- a/src/Changelog.txt +++ b/src/Changelog.txt @@ -8,6 +8,7 @@ Released: unreleased * TortoiseGitBlame: Allow to highlight lines by age of last modification * Fixed issue #1376: Daemon starting from Tortoise UI * Fixed issue #1737: Make a button to rename remote + * Repository Browser: Allow to copy tree / blob hashes to clipboard == Bug Fixes == * Fixed issue #1729: crash when commit diff --git a/src/TortoiseProc/RepositoryBrowser.cpp b/src/TortoiseProc/RepositoryBrowser.cpp index 37d840881..b4449442e 100644 --- a/src/TortoiseProc/RepositoryBrowser.cpp +++ b/src/TortoiseProc/RepositoryBrowser.cpp @@ -321,9 +321,11 @@ int CRepositoryBrowser::ReadTreeRecursive(git_repository &repo, git_tree * tree, if (object == NULL) continue; + const git_oid *oid = git_object_id(object); CShadowFilesTree * pNextTree = &treeroot->m_ShadowTree[base]; pNextTree->m_sName = base; pNextTree->m_pParent = treeroot; + pNextTree->m_hash = CGitHash((char *)oid->id); if (mode & S_IFDIR) { @@ -344,8 +346,6 @@ int CRepositoryBrowser::ReadTreeRecursive(git_repository &repo, git_tree * tree, } else { - const git_oid * oid = git_object_id(object); - git_blob * blob; git_blob_lookup(&blob, &repo, oid); if (blob == NULL) @@ -586,6 +586,7 @@ void CRepositoryBrowser::ShowContextMenu(CPoint point, TShadowFilesTreeList &sel bAddSeparator = false; popupMenu.AppendMenuIcon(eCmd_CopyPath, IDS_STATUSLIST_CONTEXT_COPY, IDI_COPYCLIP); + popupMenu.AppendMenuIcon(eCmd_CopyHash, IDS_COPY_COMMIT_HASH, IDI_COPYCLIP); eCmd cmd = (eCmd)popupMenu.TrackPopupMenuEx(TPM_LEFTALIGN|TPM_RETURNCMD, point.x, point.y, this, 0); switch(cmd) @@ -651,6 +652,11 @@ void CRepositoryBrowser::ShowContextMenu(CPoint point, TShadowFilesTreeList &sel CStringUtils::WriteAsciiStringToClipboard(sClipboard); } break; + case eCmd_CopyHash: + { + CopyHashToClipboard(selectedLeafs); + } + break; } } @@ -1009,4 +1015,21 @@ bool CRepositoryBrowser::RevertItemToVersion(const CString &path) } return true; +} + +void CRepositoryBrowser::CopyHashToClipboard(TShadowFilesTreeList &selectedLeafs) +{ + if (!selectedLeafs.empty()) + { + CString sClipdata; + bool first = true; + for (int i = 0; i < selectedLeafs.size(); i++) + { + if (!first) + sClipdata += _T("\r\n"); + sClipdata += selectedLeafs[i]->m_hash; + first = false; + } + CStringUtils::WriteAsciiStringToClipboard(sClipdata, GetSafeHwnd()); + } } \ No newline at end of file diff --git a/src/TortoiseProc/RepositoryBrowser.h b/src/TortoiseProc/RepositoryBrowser.h index 13f31a8c6..2dbd0caaa 100644 --- a/src/TortoiseProc/RepositoryBrowser.h +++ b/src/TortoiseProc/RepositoryBrowser.h @@ -21,6 +21,7 @@ #include #include "StandAloneDlg.h" +#include "GitHash.h" #define REPOBROWSER_CTRL_MIN_WIDTH 20 @@ -39,6 +40,7 @@ public: {} CString m_sName; + CGitHash m_hash; size_t m_iSize; bool m_bFolder; @@ -85,6 +87,7 @@ public: eCmd_Revert, eCmd_SaveAs, eCmd_CopyPath, + eCmd_CopyHash, }; enum eCol @@ -164,4 +167,5 @@ private: afx_msg void OnCaptureChanged(CWnd *pWnd); afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg void OnLButtonUp(UINT nFlags, CPoint point); + afx_msg void CopyHashToClipboard(TShadowFilesTreeList &selectedLeafs); }; -- 2.11.4.GIT