From 71ba910665a7f82617a94a07820be56e1b5691fd Mon Sep 17 00:00:00 2001 From: Sup Yut Sum Date: Fri, 17 Oct 2014 19:33:10 +0800 Subject: [PATCH] Implement git describe in Log Dialog Signed-off-by: Sup Yut Sum --- src/TortoiseProc/LogDlg.cpp | 37 ++++++++++++++++++++++++++++++++++++- src/TortoiseProc/LogDlg.h | 1 + src/Utils/SmartLibgit2Ref.h | 15 +++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/TortoiseProc/LogDlg.cpp b/src/TortoiseProc/LogDlg.cpp index cb4e306ab..2222c4e9b 100644 --- a/src/TortoiseProc/LogDlg.cpp +++ b/src/TortoiseProc/LogDlg.cpp @@ -96,6 +96,7 @@ CLogDlg::CLogDlg(CWnd* pParent /*=NULL*/) m_bShowGravatar = !!CRegDWORD(_T("Software\\TortoiseGit\\EnableGravatar"), FALSE); m_regbShowGravatar = CRegDWORD(_T("Software\\TortoiseGit\\LogDialog\\ShowGravatar\\") + str, m_bShowGravatar); m_bShowGravatar = !!m_regbShowGravatar; + m_bShowDescribe = !!CRegDWORD(_T("Software\\TortoiseGit\\ShowDescribe")); } CLogDlg::~CLogDlg() @@ -658,6 +659,32 @@ BOOL FindGitHash(const CString& msg, int offset, CWnd *pWnd) return positions.empty() ? FALSE : TRUE; } +static int DescribeCommit(CGitHash& hash, CString& result) +{ + CAutoRepository repo(g_Git.GetGitRepository()); + if (!repo) + return -1; + CAutoObject commit; + if (git_object_lookup(commit.GetPointer(), repo, (const git_oid *)hash.m_hash, GIT_OBJ_COMMIT)) + return -1; + + CAutoDescribeResult describe; + git_describe_options describe_options = GIT_DESCRIBE_OPTIONS_INIT; + describe_options.describe_strategy = CRegDWORD(_T("Software\\TortoiseGit\\DescribeStrategy"), GIT_DESCRIBE_DEFAULT); + if (git_describe_commit(describe.GetPointer(), (git_object *)commit, &describe_options)) + return -1; + + CAutoBuf describe_buf; + git_describe_format_options format_options = GIT_DESCRIBE_FORMAT_OPTIONS_INIT; + format_options.abbreviated_size = CRegDWORD(_T("Software\\TortoiseGit\\DescribeAbbreviatedSize"), GIT_DESCRIBE_DEFAULT_ABBREVIATED_SIZE); + format_options.always_use_long_format = CRegDWORD(_T("Software\\TortoiseGit\\DescribeAlwaysLong")); + if (git_describe_format(describe_buf, describe, &format_options)) + return -1; + + result = CUnicodeUtils::GetUnicode(describe_buf->ptr); + return 0; +} + void CLogDlg::FillLogMessageCtrl(bool bShow /* = true*/) { // we fill here the log message rich edit control, @@ -715,8 +742,16 @@ void CLogDlg::FillLogMessageCtrl(bool bShow /* = true*/) GitRev* pLogEntry = reinterpret_cast(m_LogList.m_arShownList.SafeGetAt(selIndex)); { + CString out_describe; + if (m_bShowDescribe) + { + CString result; + if (!DescribeCommit(pLogEntry->m_CommitHash, result)) + out_describe = _T("Describe: ") + result + _T("\r\n"); + } + // set the log message text - pMsgView->SetWindowText(CString(MAKEINTRESOURCE(IDS_HASH)) + _T(": ") + pLogEntry->m_CommitHash.ToString() + _T("\r\n\r\n")); + pMsgView->SetWindowText(CString(MAKEINTRESOURCE(IDS_HASH)) + _T(": ") + pLogEntry->m_CommitHash.ToString() + _T("\r\n") + out_describe + _T("\r\n")); // turn bug ID's into links if the bugtraq: properties have been set // and we can find a match of those in the log message diff --git a/src/TortoiseProc/LogDlg.h b/src/TortoiseProc/LogDlg.h index 6068393fe..b4eab7c6a 100644 --- a/src/TortoiseProc/LogDlg.h +++ b/src/TortoiseProc/LogDlg.h @@ -227,6 +227,7 @@ private: bool m_bShowLocalBranches; bool m_bShowRemoteBranches; bool m_bShowGravatar; + bool m_bShowDescribe; bool m_bNoMerges; int m_iCompressedGraph; BOOL m_bWalkBehavior; diff --git a/src/Utils/SmartLibgit2Ref.h b/src/Utils/SmartLibgit2Ref.h index 3bd44e82b..daf6a359e 100644 --- a/src/Utils/SmartLibgit2Ref.h +++ b/src/Utils/SmartLibgit2Ref.h @@ -445,6 +445,21 @@ protected: } }; +class CAutoDescribeResult : public CSmartLibgit2Ref +{ +public: + ~CAutoDescribeResult() + { + CleanUp(); + } + +protected: + virtual void FreeRef() + { + git_describe_result_free(m_Ref); + } +}; + template class CSmartBuffer : public FreeFunction { -- 2.11.4.GIT