From ddeb1e256cd4b3b415f3bca68e66c2a5e7508334 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Sat, 14 Jan 2012 02:31:26 +0100 Subject: [PATCH] share code for calculation of relative times in log Signed-off-by: Sven Strickroth --- src/TortoiseGitBlame/TortoiseGitBlame.vcproj | 12 +- src/TortoiseGitBlame/TortoiseGitBlameView.cpp | 4 +- src/TortoiseProc/AppUtils.cpp | 139 --------------------- src/TortoiseProc/AppUtils.h | 26 +--- src/TortoiseProc/BranchCombox.h | 4 +- src/TortoiseProc/FileDiffDlg.cpp | 7 +- src/TortoiseProc/GitLogListBase.cpp | 8 +- .../LoglistUtils.cpp} | 18 +-- .../LoglistUtils.h} | 12 +- src/TortoiseProc/RebaseDlg.cpp | 3 +- src/TortoiseProc/SyncDlg.cpp | 3 +- src/TortoiseProc/TortoiseProc.vcproj | 8 ++ 12 files changed, 49 insertions(+), 195 deletions(-) rename src/{TortoiseGitBlame/TortoiseGitBlameAppUtils.cpp => TortoiseProc/LoglistUtils.cpp} (86%) rename src/{TortoiseGitBlame/TortoiseGitBlameAppUtils.h => TortoiseProc/LoglistUtils.h} (89%) diff --git a/src/TortoiseGitBlame/TortoiseGitBlame.vcproj b/src/TortoiseGitBlame/TortoiseGitBlame.vcproj index f769b55c2..25382d292 100644 --- a/src/TortoiseGitBlame/TortoiseGitBlame.vcproj +++ b/src/TortoiseGitBlame/TortoiseGitBlame.vcproj @@ -428,6 +428,10 @@ > + + @@ -496,10 +500,6 @@ > - - @@ -522,6 +522,10 @@ > + + diff --git a/src/TortoiseGitBlame/TortoiseGitBlameView.cpp b/src/TortoiseGitBlame/TortoiseGitBlameView.cpp index 8be38134b..40c12c623 100644 --- a/src/TortoiseGitBlame/TortoiseGitBlameView.cpp +++ b/src/TortoiseGitBlame/TortoiseGitBlameView.cpp @@ -30,7 +30,7 @@ #include "TortoiseGitBlameView.h" #include "MainFrm.h" #include "EditGotoDlg.h" -#include "TortoiseGitBlameAppUtils.h" +#include "LoglistUtils.h" #include "FileTextLines.h" #include "UniCodeUtils.h" #include "MenuEncode.h" @@ -2786,7 +2786,7 @@ void CTortoiseGitBlameView::OnMouseHover(UINT nFlags, CPoint point) CString str; str.Format(_T("%s: %s\n%s: %s\n%s: %s\n%s:\n%s\n%s"), m_sRev, pRev->m_CommitHash.ToString(), m_sAuthor, pRev->GetAuthorName(), - m_sDate, CAppUtils::FormatDateAndTime(pRev->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes), + m_sDate, CLoglistUtils::FormatDateAndTime(pRev->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes), m_sMessage, pRev->GetSubject(), pRev->GetBody()); diff --git a/src/TortoiseProc/AppUtils.cpp b/src/TortoiseProc/AppUtils.cpp index 5633b3f67..f534cc82c 100644 --- a/src/TortoiseProc/AppUtils.cpp +++ b/src/TortoiseProc/AppUtils.cpp @@ -1759,145 +1759,6 @@ bool CAppUtils::ConflictEdit(CTGitPath &path,bool /*bAlternativeTool*/,bool reve return bRet; } -/** - * FUNCTION : FormatDateAndTime - * DESCRIPTION : Generates a displayable string from a CTime object in - * system short or long format or as a relative value - * cTime - the time - * option - DATE_SHORTDATE or DATE_LONGDATE - * bIncluedeTime - whether to show time as well as date - * bRelative - if true then relative time is shown if reasonable - * If HKCU\Software\TortoiseGit\UseSystemLocaleForDates is 0 then use fixed format - * rather than locale - * RETURN : CString containing date/time - */ -CString CAppUtils::FormatDateAndTime( const CTime& cTime, DWORD option, bool bIncludeTime /*=true*/, - bool bRelative /*=false*/) -{ - CString datetime; - if ( bRelative ) - { - datetime = ToRelativeTimeString( cTime ); - } - else - { - // should we use the locale settings for formatting the date/time? - if (CRegDWORD(_T("Software\\TortoiseGit\\UseSystemLocaleForDates"), TRUE)) - { - // yes - SYSTEMTIME sysTime; - cTime.GetAsSystemTime( sysTime ); - - TCHAR buf[100]; - - GetDateFormat(LOCALE_USER_DEFAULT, option, &sysTime, NULL, buf, - _countof(buf) - 1); - datetime = buf; - if ( bIncludeTime ) - { - datetime += _T(" "); - GetTimeFormat(LOCALE_USER_DEFAULT, 0, &sysTime, NULL, buf, _countof(buf) - 1); - datetime += buf; - } - } - else - { - // no, so fixed format - if ( bIncludeTime ) - { - datetime = cTime.Format(_T("%Y-%m-%d %H:%M:%S")); - } - else - { - datetime = cTime.Format(_T("%Y-%m-%d")); - } - } - } - return datetime; -} - -/** - * Converts a given time to a relative display string (relative to current time) - * Given time must be in local timezone - */ -CString CAppUtils::ToRelativeTimeString(CTime time) -{ - CString answer; - // convert to COleDateTime - SYSTEMTIME sysTime; - time.GetAsSystemTime( sysTime ); - COleDateTime oleTime( sysTime ); - answer = ToRelativeTimeString(oleTime, COleDateTime::GetCurrentTime()); - return answer; -} - -/** - * Generates a display string showing the relative time between the two given times as COleDateTimes - */ -CString CAppUtils::ToRelativeTimeString(COleDateTime time,COleDateTime RelativeTo) -{ - CString answer; - COleDateTimeSpan ts = RelativeTo - time; - //years - if(fabs(ts.GetTotalDays()) >= 3*365) - { - answer = ExpandRelativeTime( (int)ts.GetTotalDays()/365, IDS_YEAR_AGO, IDS_YEARS_AGO ); - } - //Months - if(fabs(ts.GetTotalDays()) >= 60) - { - answer = ExpandRelativeTime( (int)ts.GetTotalDays()/30, IDS_MONTH_AGO, IDS_MONTHS_AGO ); - return answer; - } - //Weeks - if(fabs(ts.GetTotalDays()) >= 14) - { - answer = ExpandRelativeTime( (int)ts.GetTotalDays()/7, IDS_WEEK_AGO, IDS_WEEKS_AGO ); - return answer; - } - //Days - if(fabs(ts.GetTotalDays()) >= 2) - { - answer = ExpandRelativeTime( (int)ts.GetTotalDays(), IDS_DAY_AGO, IDS_DAYS_AGO ); - return answer; - } - //hours - if(fabs(ts.GetTotalHours()) >= 2) - { - answer = ExpandRelativeTime( (int)ts.GetTotalHours(), IDS_HOUR_AGO, IDS_HOURS_AGO ); - return answer; - } - //minutes - if(fabs(ts.GetTotalMinutes()) >= 2) - { - answer = ExpandRelativeTime( (int)ts.GetTotalMinutes(), IDS_MINUTE_AGO, IDS_MINUTES_AGO ); - return answer; - } - //seconds - answer = ExpandRelativeTime( (int)ts.GetTotalSeconds(), IDS_SECOND_AGO, IDS_SECONDS_AGO ); - return answer; -} - -/** - * Passed a value and two resource string ids - * if count is 1 then FormatString is called with format_1 and the value - * otherwise format_2 is used - * the formatted string is returned -*/ -CString CAppUtils::ExpandRelativeTime( int count, UINT format_1, UINT format_n ) -{ - CString answer; - if ( count == 1 ) - { - answer.FormatMessage( format_1, count ); - } - else - { - answer.FormatMessage( format_n, count ); - } - return answer; -} - bool CAppUtils::IsSSHPutty() { CString sshclient=g_Git.m_Environment.GetEnv(_T("GIT_SSH")); diff --git a/src/TortoiseProc/AppUtils.h b/src/TortoiseProc/AppUtils.h index 1d297898c..a57181beb 100644 --- a/src/TortoiseProc/AppUtils.h +++ b/src/TortoiseProc/AppUtils.h @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2008-2011 - TortoiseGit +// Copyright (C) 2008-2012 - TortoiseGit // Copyright (C) 2003-2008 - TortoiseSVN // This program is free software; you can redistribute it and/or @@ -162,25 +162,6 @@ public: static bool IgnoreFile(CTGitPathList &filelist,bool IsMask); static bool GitReset(CString *CommitHash,int type=1); static bool ConflictEdit(CTGitPath &file,bool bAlternativeTool=false,bool revertTheirMy=false); - /** - * FUNCTION : FormatDateAndTime - * DESCRIPTION : Generates a displayable string from a CTime object in - * system short or long format or as a relative value - * cTime - the time - * option - DATE_SHORTDATE or DATE_LONGDATE - * bIncluedeTime - whether to show time as well as date - * bRelative - if true then relative time is shown if reasonable - * If HKCU\Software\TortoiseGit\UseSystemLocaleForDates is 0 then use fixed format - * rather than locale - * RETURN : CString containing date/time - */ - static CString FormatDateAndTime( const CTime& cTime, DWORD option, bool bIncludeTime=true, - bool bRelative=false ); - /** - * Converts a given time to a relative display string (relative to current time) - * Given time must be in local timezone - */ - static CString ToRelativeTimeString(CTime time); static CString GetMergeTempFile(CString str,CTGitPath &merge); static bool StashSave(); @@ -229,11 +210,6 @@ public: private: static CString PickDiffTool(const CTGitPath& file1, const CTGitPath& file2); static bool GetMimeType(const CTGitPath& file, CString& mimetype); - /** - * Generates a display string showing the relative time between the two given times as COleDateTimes - */ - static CString ToRelativeTimeString(COleDateTime time,COleDateTime RelativeTo); - static CString ExpandRelativeTime( int count, UINT format_1, UINT format_n ); static void DescribeFile(bool mode, bool base,CString &descript); }; diff --git a/src/TortoiseProc/BranchCombox.h b/src/TortoiseProc/BranchCombox.h index 459aa8793..6a621a384 100644 --- a/src/TortoiseProc/BranchCombox.h +++ b/src/TortoiseProc/BranchCombox.h @@ -4,7 +4,7 @@ #include "BrowseRefsDlg.h" #include "HistoryCombo.h" #include "HistoryCombo.h" -#include "AppUtils.h" +#include "LoglistUtils.h" #include "UnicodeUtils.h" #include "Tooltip.h" @@ -138,7 +138,7 @@ protected: tooltip.Format(_T("CommitHash: %s\nCommit by: %s\nDate:%s\n%s\n%s"), rev.m_CommitHash.ToString(), rev.GetAuthorName(), - CAppUtils::FormatDateAndTime(rev.GetAuthorDate(),DATE_LONGDATE), + CLoglistUtils::FormatDateAndTime(rev.GetAuthorDate(), DATE_LONGDATE), rev.GetSubject(), rev.GetBody()); diff --git a/src/TortoiseProc/FileDiffDlg.cpp b/src/TortoiseProc/FileDiffDlg.cpp index ec155dbec..1c8a6c504 100644 --- a/src/TortoiseProc/FileDiffDlg.cpp +++ b/src/TortoiseProc/FileDiffDlg.cpp @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2008-2011 - TortoiseGit +// Copyright (C) 2008-2012 - TortoiseGit // Copyright (C) 2003-2008 - TortoiseSVN // This program is free software; you can redistribute it and/or @@ -32,6 +32,7 @@ #include ".\filediffdlg.h" #include "gitdiff.h" #include "LoglistCommonResource.h" +#include "LoglistUtils.h" #include "BrowseRefsDlg.h" #include "LogDlg.h" #include "RefLogDlg.h" @@ -732,7 +733,7 @@ void CFileDiffDlg::SetURLLabels(int mask) { SetDlgItemText(IDC_FIRSTURL, m_rev1.m_CommitHash.ToString().Left(8)+_T(": ")+m_rev1.GetSubject()); m_tooltips.AddTool(IDC_FIRSTURL, - CAppUtils::FormatDateAndTime( m_rev1.GetAuthorDate(), DATE_SHORTDATE, false )+_T(" ")+m_rev1.GetAuthorName()); + CLoglistUtils::FormatDateAndTime(m_rev1.GetAuthorDate(), DATE_SHORTDATE, false) + _T(" ") + m_rev1.GetAuthorName()); } @@ -741,7 +742,7 @@ void CFileDiffDlg::SetURLLabels(int mask) SetDlgItemText(IDC_SECONDURL,m_rev2.m_CommitHash.ToString().Left(8)+_T(": ")+m_rev2.GetSubject()); m_tooltips.AddTool(IDC_SECONDURL, - CAppUtils::FormatDateAndTime( m_rev2.GetAuthorDate(), DATE_SHORTDATE, false )+_T(" ")+m_rev2.GetAuthorName()); + CLoglistUtils::FormatDateAndTime(m_rev2.GetAuthorDate(), DATE_SHORTDATE, false) + _T(" ") + m_rev2.GetAuthorName()); } this->GetDlgItem(IDC_REV2GROUP)->SetWindowText(_T("Version 2 (Base)")); diff --git a/src/TortoiseProc/GitLogListBase.cpp b/src/TortoiseProc/GitLogListBase.cpp index 8dc4103c8..dfd3d084b 100644 --- a/src/TortoiseProc/GitLogListBase.cpp +++ b/src/TortoiseProc/GitLogListBase.cpp @@ -37,7 +37,7 @@ #include "Logdlg.h" #include "MessageBox.h" #include "Registry.h" -#include "AppUtils.h" +#include "LoglistUtils.h" #include "PathUtils.h" #include "StringUtils.h" #include "UnicodeUtils.h" @@ -1292,7 +1292,7 @@ void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult) case this->LOGLIST_DATE: //Date if ( pLogEntry && (!pLogEntry->m_CommitHash.IsEmpty()) ) lstrcpyn(pItem->pszText, - CAppUtils::FormatDateAndTime( pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes ), + CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes), pItem->cchTextMax); break; @@ -1314,7 +1314,7 @@ void CGitLogListBase::OnLvnGetdispinfoLoglist(NMHDR *pNMHDR, LRESULT *pResult) case this->LOGLIST_COMMIT_DATE: //Commit Date if (pLogEntry) lstrcpyn(pItem->pszText, - CAppUtils::FormatDateAndTime( pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes ), + CLoglistUtils::FormatDateAndTime(pLogEntry->GetCommitterDate(), m_DateFormat, true, m_bRelativeTimes), pItem->cchTextMax); break; case this->LOGLIST_BUG: //Bug ID @@ -1883,7 +1883,7 @@ void CGitLogListBase::CopySelectionToClipBoard(bool HashOnly) (LPCTSTR)sRev, pLogEntry->m_CommitHash.ToString(), (LPCTSTR)sAuthor, (LPCTSTR)pLogEntry->GetAuthorName(), (LPCTSTR)sDate, - (LPCTSTR)CAppUtils::FormatDateAndTime( pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes ), + (LPCTSTR)CLoglistUtils::FormatDateAndTime(pLogEntry->GetAuthorDate(), m_DateFormat, true, m_bRelativeTimes), (LPCTSTR)sMessage, pLogEntry->GetSubject().Trim() + _T("\r\n\r\n") + body.Trim(), (LPCTSTR)sPaths); sClipdata += sLogCopyText; diff --git a/src/TortoiseGitBlame/TortoiseGitBlameAppUtils.cpp b/src/TortoiseProc/LoglistUtils.cpp similarity index 86% rename from src/TortoiseGitBlame/TortoiseGitBlameAppUtils.cpp rename to src/TortoiseProc/LoglistUtils.cpp index a7b6e2b5b..d327afe47 100644 --- a/src/TortoiseGitBlame/TortoiseGitBlameAppUtils.cpp +++ b/src/TortoiseProc/LoglistUtils.cpp @@ -1,6 +1,7 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2003-2011 - TortoiseGit +// Copyright (C) 2008-2012 - TortoiseGit +// Copyright (C) 2003-2008 - TortoiseSVN // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -19,14 +20,14 @@ #include "StdAfx.h" #include "math.h" #include "..\Resources\LoglistCommonResource.h" -#include "TortoiseGitBlameAppUtils.h" +#include "LoglistUtils.h" #include "Registry.h" -CAppUtils::CAppUtils(void) +CLoglistUtils::CLoglistUtils(void) { } -CAppUtils::~CAppUtils(void) +CLoglistUtils::~CLoglistUtils(void) { } @@ -42,7 +43,7 @@ CAppUtils::~CAppUtils(void) * rather than locale * RETURN : CString containing date/time */ -CString CAppUtils::FormatDateAndTime( const CTime& cTime, DWORD option, bool bIncludeTime /*=true*/, +CString CLoglistUtils::FormatDateAndTime( const CTime& cTime, DWORD option, bool bIncludeTime /*=true*/, bool bRelative /*=false*/) { CString datetime; @@ -91,7 +92,7 @@ CString CAppUtils::FormatDateAndTime( const CTime& cTime, DWORD option, bool bIn * Converts a given time to a relative display string (relative to current time) * Given time must be in local timezone */ -CString CAppUtils::ToRelativeTimeString(CTime time) +CString CLoglistUtils::ToRelativeTimeString(CTime time) { CString answer; // convert to COleDateTime @@ -105,7 +106,7 @@ CString CAppUtils::ToRelativeTimeString(CTime time) /** * Generates a display string showing the relative time between the two given times as COleDateTimes */ -CString CAppUtils::ToRelativeTimeString(COleDateTime time,COleDateTime RelativeTo) +CString CLoglistUtils::ToRelativeTimeString(COleDateTime time,COleDateTime RelativeTo) { CString answer; COleDateTimeSpan ts = RelativeTo - time; @@ -155,7 +156,7 @@ CString CAppUtils::ToRelativeTimeString(COleDateTime time,COleDateTime RelativeT * otherwise format_2 is used * the formatted string is returned */ -CString CAppUtils::ExpandRelativeTime( int count, UINT format_1, UINT format_n ) +CString CLoglistUtils::ExpandRelativeTime( int count, UINT format_1, UINT format_n ) { CString answer; if ( count == 1 ) @@ -168,4 +169,3 @@ CString CAppUtils::ExpandRelativeTime( int count, UINT format_1, UINT format_n ) } return answer; } - diff --git a/src/TortoiseGitBlame/TortoiseGitBlameAppUtils.h b/src/TortoiseProc/LoglistUtils.h similarity index 89% rename from src/TortoiseGitBlame/TortoiseGitBlameAppUtils.h rename to src/TortoiseProc/LoglistUtils.h index 2a5d429fe..ecef10b20 100644 --- a/src/TortoiseGitBlame/TortoiseGitBlameAppUtils.h +++ b/src/TortoiseProc/LoglistUtils.h @@ -1,5 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control +// Copyright (C) 2008-2012 - TortoiseGit // Copyright (C) 2003-2008 - TortoiseSVN // This program is free software; you can redistribute it and/or @@ -17,15 +18,16 @@ // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // #pragma once + /** - * \ingroup TortoiseGitBlame - * An utility class with static functions. + * \ingroup TortoiseProc + * An utility class with static functions for GitLoglist. */ -class CAppUtils +class CLoglistUtils { public: - CAppUtils(void); - ~CAppUtils(void); + CLoglistUtils(void); + ~CLoglistUtils(void); /** * FUNCTION : FormatDateAndTime diff --git a/src/TortoiseProc/RebaseDlg.cpp b/src/TortoiseProc/RebaseDlg.cpp index ba181743e..84faf9360 100644 --- a/src/TortoiseProc/RebaseDlg.cpp +++ b/src/TortoiseProc/RebaseDlg.cpp @@ -25,6 +25,7 @@ #include "TortoiseProc.h" #include "RebaseDlg.h" #include "AppUtils.h" +#include "LoglistUtils.h" #include "MessageBox.h" #include "UnicodeUtils.h" #include "BrowseRefsDlg.h" @@ -596,7 +597,7 @@ void CRebaseDlg::AddBranchToolTips(CHistoryCombo *pBranch) tooltip.Format(_T("CommitHash:%s\nCommit by: %s %s\n %s \n %s"), rev.m_CommitHash.ToString(), rev.GetAuthorName(), - CAppUtils::FormatDateAndTime(rev.GetAuthorDate(),DATE_LONGDATE), + CLoglistUtils::FormatDateAndTime(rev.GetAuthorDate(), DATE_LONGDATE), rev.GetSubject(), rev.GetBody()); diff --git a/src/TortoiseProc/SyncDlg.cpp b/src/TortoiseProc/SyncDlg.cpp index fb26aa5cb..d245ed977 100644 --- a/src/TortoiseProc/SyncDlg.cpp +++ b/src/TortoiseProc/SyncDlg.cpp @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2008-2009 - TortoiseGit +// Copyright (C) 2008-2012 - TortoiseGit // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -23,6 +23,7 @@ #include "stdafx.h" #include "TortoiseProc.h" #include "SyncDlg.h" +#include "AppUtils.h" #include "progressdlg.h" #include "MessageBox.h" #include "ImportPatchDlg.h" diff --git a/src/TortoiseProc/TortoiseProc.vcproj b/src/TortoiseProc/TortoiseProc.vcproj index 69a8c7fd9..47f8df2ce 100644 --- a/src/TortoiseProc/TortoiseProc.vcproj +++ b/src/TortoiseProc/TortoiseProc.vcproj @@ -1189,6 +1189,14 @@ > + + + + -- 2.11.4.GIT