Compare commits
3 Commits
5f36d59bf8
...
52221ac116
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
52221ac116 | ||
|
|
c05a8cc0e0 | ||
|
|
e90f37966f |
@@ -818,6 +818,8 @@ int main(int argc, TCHAR* argv[], TCHAR* envp[])
|
|||||||
int nCmdRet = HandleCreateTagInteractive();
|
int nCmdRet = HandleCreateTagInteractive();
|
||||||
LogCommandEnd(_T("interactive"), dwStartTick, nCmdRet);
|
LogCommandEnd(_T("interactive"), dwStartTick, nCmdRet);
|
||||||
PrintCommandFailedWithCode(_T("interactive"), nCmdRet);
|
PrintCommandFailedWithCode(_T("interactive"), nCmdRet);
|
||||||
|
// 暂停,便于查看输出日志(Windows 控制台)
|
||||||
|
system("pause");
|
||||||
return nCmdRet;
|
return nCmdRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -230,6 +230,42 @@ int HandleCreateTagInteractive()
|
|||||||
return 34;
|
return 34;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 已验证本地创建成功后,尝试推送到远程 origin
|
||||||
|
CString strPushCmd;
|
||||||
|
strPushCmd.Format(_T("cmd /c git push origin %s"), QuoteCmdArg(strNewTag).GetString());
|
||||||
|
CString strPushResult = StartProcess(NULL, strPushCmd.GetBuffer(), lpRepoPath);
|
||||||
|
strPushCmd.ReleaseBuffer();
|
||||||
|
strPushResult.Trim();
|
||||||
|
if (strPushResult.Left(6).CompareNoCase(_T("fatal:")) == 0 || strPushResult.Left(5).CompareNoCase(_T("error")) == 0)
|
||||||
|
{
|
||||||
|
_tprintf(_T("警告: 推送标签到远程失败: %s\n"), strPushResult.GetString());
|
||||||
|
|
||||||
|
// 推送失败:尝试删除本地标签,避免残留
|
||||||
|
CString strDeleteCmd;
|
||||||
|
strDeleteCmd.Format(_T("cmd /c git tag -d %s"), QuoteCmdArg(strNewTag).GetString());
|
||||||
|
CString strDeleteResult = StartProcess(NULL, strDeleteCmd.GetBuffer(), lpRepoPath);
|
||||||
|
strDeleteCmd.ReleaseBuffer();
|
||||||
|
strDeleteResult.Trim();
|
||||||
|
|
||||||
|
if (strDeleteResult.Left(6).CompareNoCase(_T("fatal:")) == 0 || strDeleteResult.Left(5).CompareNoCase(_T("error")) == 0)
|
||||||
|
{
|
||||||
|
_tprintf(_T("错误: 推送失败,且删除本地标签失败: %s\n"), strDeleteResult.GetString());
|
||||||
|
// 返回错误码 36 表示推送失败(删除也失败)
|
||||||
|
return 36;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_tprintf(_T("已删除本地标签: %s\n"), strNewTag.GetString());
|
||||||
|
// 返回错误码 36 表示推送失败,但本地标签已清理
|
||||||
|
return 36;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_tprintf(_T("成功: 推送标签到远程 origin: %s\n"), strNewTag.GetString());
|
||||||
|
}
|
||||||
|
|
||||||
_tprintf(_T("成功: 创建标签 %s\n"), strNewTag.GetString());
|
_tprintf(_T("成功: 创建标签 %s\n"), strNewTag.GetString());
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -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