修正:当当天提交数为0时,以最后一次提交日期重新生成mmdd.id值。
This commit is contained in:
@@ -122,16 +122,14 @@ BOOL GetLastMajorMinorTag(LPCTSTR lpRepoPath, const CString& strBranch, CString&
|
|||||||
return !strTag.IsEmpty();
|
return !strTag.IsEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetTodayFileVersionDate(UINT& nYY, UINT& nMMDD)
|
void GetFileVersionDateFromSystemTime(const SYSTEMTIME& stLocal, UINT& nYY, UINT& nMMDD)
|
||||||
{
|
{
|
||||||
SYSTEMTIME stLocal = { 0 };
|
|
||||||
::GetLocalTime(&stLocal);
|
|
||||||
|
|
||||||
nYY = stLocal.wYear % 100;
|
nYY = stLocal.wYear % 100;
|
||||||
|
// 为了让版本号对齐4位,月份从1-12映射到11-22;
|
||||||
nMMDD = (stLocal.wMonth + 10) * 100 + stLocal.wDay;
|
nMMDD = (stLocal.wMonth + 10) * 100 + stLocal.wDay;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL GetTodayBranchCommitCount(LPCTSTR lpRepoPath, const CString& strBranch, UINT& nId)
|
BOOL TryGetBranchCommitCountByDate(LPCTSTR lpRepoPath, const CString& strBranch, const SYSTEMTIME& stDate, UINT& nId)
|
||||||
{
|
{
|
||||||
nId = 0;
|
nId = 0;
|
||||||
if (strBranch.IsEmpty())
|
if (strBranch.IsEmpty())
|
||||||
@@ -139,11 +137,8 @@ BOOL GetTodayBranchCommitCount(LPCTSTR lpRepoPath, const CString& strBranch, UIN
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
SYSTEMTIME stLocal = { 0 };
|
|
||||||
::GetLocalTime(&stLocal);
|
|
||||||
|
|
||||||
CString strDate;
|
CString strDate;
|
||||||
strDate.Format(_T("%04u-%02u-%02u"), stLocal.wYear, stLocal.wMonth, stLocal.wDay);
|
strDate.Format(_T("%04u-%02u-%02u"), stDate.wYear, stDate.wMonth, stDate.wDay);
|
||||||
|
|
||||||
CString strCmd;
|
CString strCmd;
|
||||||
strCmd.Format(
|
strCmd.Format(
|
||||||
@@ -172,6 +167,93 @@ BOOL GetTodayBranchCommitCount(LPCTSTR lpRepoPath, const CString& strBranch, UIN
|
|||||||
return TryParseUInt16(strCount, nId);
|
return TryParseUInt16(strCount, nId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOL TryGetLastBranchCommitDate(LPCTSTR lpRepoPath, const CString& strBranch, SYSTEMTIME& stDate)
|
||||||
|
{
|
||||||
|
::ZeroMemory(&stDate, sizeof(stDate));
|
||||||
|
if (strBranch.IsEmpty())
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
CString strCmd;
|
||||||
|
strCmd.Format(_T("cmd /c git log -1 --date=short --format=%%cd \"%s\""), strBranch.GetString());
|
||||||
|
|
||||||
|
CString strDate = StartProcess(NULL, strCmd.GetBuffer(), lpRepoPath);
|
||||||
|
strCmd.ReleaseBuffer();
|
||||||
|
|
||||||
|
if (strDate.IsEmpty())
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
strDate.Replace(_T("\r"), _T(""));
|
||||||
|
strDate.Replace(_T("\n"), _T(""));
|
||||||
|
strDate.Trim();
|
||||||
|
|
||||||
|
if (strDate.IsEmpty() || strDate.Left(6).CompareNoCase(_T("fatal:")) == 0)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int nYear = 0;
|
||||||
|
unsigned int nMonth = 0;
|
||||||
|
unsigned int nDay = 0;
|
||||||
|
if (_stscanf_s(strDate.GetString(), _T("%u-%u-%u"), &nYear, &nMonth, &nDay) != 3)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
stDate.wYear = static_cast<WORD>(nYear);
|
||||||
|
stDate.wMonth = static_cast<WORD>(nMonth);
|
||||||
|
stDate.wDay = static_cast<WORD>(nDay);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL ResolveFileVersionDateAndCommitCount(LPCTSTR lpRepoPath, const CString& strBranch, UINT& nYY, UINT& nMMDD, UINT& nId)
|
||||||
|
{
|
||||||
|
nYY = 0;
|
||||||
|
nMMDD = 0;
|
||||||
|
nId = 0;
|
||||||
|
|
||||||
|
SYSTEMTIME stTargetDate = { 0 };
|
||||||
|
::GetLocalTime(&stTargetDate);
|
||||||
|
|
||||||
|
UINT nTodayCommitCount = 0;
|
||||||
|
if (!TryGetBranchCommitCountByDate(lpRepoPath, strBranch, stTargetDate, nTodayCommitCount))
|
||||||
|
{
|
||||||
|
_tprintf(_T("错误: 获取当天提交数量失败\n"));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nTodayCommitCount == 0)
|
||||||
|
{
|
||||||
|
_tprintf(_T("当天提交数量为0,将获取最后一次提交日期\n"));
|
||||||
|
|
||||||
|
if (!TryGetLastBranchCommitDate(lpRepoPath, strBranch, stTargetDate))
|
||||||
|
{
|
||||||
|
_tprintf(_T("错误: 获取最后一次提交日期失败\n"));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TryGetBranchCommitCountByDate(lpRepoPath, strBranch, stTargetDate, nTodayCommitCount))
|
||||||
|
{
|
||||||
|
_tprintf(_T("错误: 获取[%s]提交数量失败\n"), strBranch.GetString());
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
_tprintf(_T("获取到最后一次提交日期: %04u-%02u-%02u, 提交数量: %u\n"),
|
||||||
|
stTargetDate.wYear, stTargetDate.wMonth, stTargetDate.wDay, nTodayCommitCount);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_tprintf(_T("获取到当天提交数量: %u\n"), nTodayCommitCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
GetFileVersionDateFromSystemTime(stTargetDate, nYY, nMMDD);
|
||||||
|
nId = nTodayCommitCount;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
int BuildVersionsFromRepo(
|
int BuildVersionsFromRepo(
|
||||||
LPCTSTR lpRepoPath,
|
LPCTSTR lpRepoPath,
|
||||||
UINT nPid,
|
UINT nPid,
|
||||||
@@ -200,7 +282,7 @@ int BuildVersionsFromRepo(
|
|||||||
|
|
||||||
if (!TryGetBidFromBranch(strBranch, nBid))
|
if (!TryGetBidFromBranch(strBranch, nBid))
|
||||||
{
|
{
|
||||||
_tprintf(_T("错误: 从分支获取 bid 失败。\n"));
|
_tprintf(_T("错误: 获取分支 bid 失败\n"));
|
||||||
return errorCodes.nBidErrorCode;
|
return errorCodes.nBidErrorCode;
|
||||||
}
|
}
|
||||||
_tprintf(_T("分支 bid: %u\n"), nBid);
|
_tprintf(_T("分支 bid: %u\n"), nBid);
|
||||||
@@ -212,7 +294,7 @@ int BuildVersionsFromRepo(
|
|||||||
{
|
{
|
||||||
if (!bUseDefaultTagWhenMissing)
|
if (!bUseDefaultTagWhenMissing)
|
||||||
{
|
{
|
||||||
_tprintf(_T("错误: 获取标签失败。\n"));
|
_tprintf(_T("错误: 获取标签失败\n"));
|
||||||
return errorCodes.nTagErrorCode;
|
return errorCodes.nTagErrorCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,23 +304,21 @@ int BuildVersionsFromRepo(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_tprintf(_T("命中最新标签: %s (major=%u minor=%u)\n"), strLastTag.GetString(), nMajor, nMinor);
|
_tprintf(_T("获取到的标签: %s (major=%u minor=%u)\n"), strLastTag.GetString(), nMajor, nMinor);
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT nYY = 0;
|
UINT nYY = 0;
|
||||||
UINT nMMDD = 0;
|
UINT nMMDD = 0;
|
||||||
GetTodayFileVersionDate(nYY, nMMDD);
|
|
||||||
|
|
||||||
UINT nId = 0;
|
UINT nId = 0;
|
||||||
if (!GetTodayBranchCommitCount(lpRepoPath, strBranch, nId))
|
if (!ResolveFileVersionDateAndCommitCount(lpRepoPath, strBranch, nYY, nMMDD, nId))
|
||||||
{
|
{
|
||||||
_tprintf(_T("错误: 获取今日分支提交计数失败。\n"));
|
_tprintf(_T("错误: 获取分支提交信息失败\n"));
|
||||||
return errorCodes.nCommitErrorCode;
|
return errorCodes.nCommitErrorCode;
|
||||||
}
|
}
|
||||||
_tprintf(_T("今日提交计数: %u\n"), nId);
|
_tprintf(_T("分支提交信息: yy=%u mmdd=%u id=%u\n"), nYY, nMMDD, nId);
|
||||||
|
|
||||||
strProductVersion.Format(_T("%u.%u.%u.%u"), nPid, nBid, nMajor, nMinor);
|
strProductVersion.Format(_T("%u.%u.%u.%u"), nPid, nBid, nMajor, nMinor);
|
||||||
strFileVersion.Format(_T("%u.%u.%u.%u"), nPid, nYY, nMMDD, nId);
|
strFileVersion.Format(_T("%u.%u.%u.%u"), nPid, nYY, nMMDD, nId);
|
||||||
_tprintf(_T("版本构建完成: ProductVersion=%s FileVersion=%s\n"), strProductVersion.GetString(), strFileVersion.GetString());
|
_tprintf(_T("文件版本信息: ProductVersion=%s FileVersion=%s\n"), strProductVersion.GetString(), strFileVersion.GetString());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -11,8 +11,6 @@ BOOL TryGetCurrentBranch(LPCTSTR lpRepoPath, CString& strBranch);
|
|||||||
BOOL TryGetBidFromBranch(const CString& strBranch, UINT& nBid);
|
BOOL TryGetBidFromBranch(const CString& strBranch, UINT& nBid);
|
||||||
BOOL TryParseTagMajorMinor(const CString& strBranch, const CString& strTag, UINT& nMajor, UINT& nMinor);
|
BOOL TryParseTagMajorMinor(const CString& strBranch, const CString& strTag, UINT& nMajor, UINT& nMinor);
|
||||||
BOOL GetLastMajorMinorTag(LPCTSTR lpRepoPath, const CString& strBranch, CString& strTag, UINT& nMajor, UINT& nMinor);
|
BOOL GetLastMajorMinorTag(LPCTSTR lpRepoPath, const CString& strBranch, CString& strTag, UINT& nMajor, UINT& nMinor);
|
||||||
void GetTodayFileVersionDate(UINT& nYY, UINT& nMMDD);
|
|
||||||
BOOL GetTodayBranchCommitCount(LPCTSTR lpRepoPath, const CString& strBranch, UINT& nId);
|
|
||||||
int BuildVersionsFromRepo(
|
int BuildVersionsFromRepo(
|
||||||
LPCTSTR lpRepoPath,
|
LPCTSTR lpRepoPath,
|
||||||
UINT nPid,
|
UINT nPid,
|
||||||
|
|||||||
Reference in New Issue
Block a user