Git 当有多个作者使用版本控制时,如何跟踪库的生成计数?
我不知道这是否是人们经常做的事情,但我个人总是记录我构建代码的次数。也就是说,我调用Git 当有多个作者使用版本控制时,如何跟踪库的生成计数?,git,svn,version-control,merge,build-numbers,Git,Svn,Version Control,Merge,Build Numbers,我不知道这是否是人们经常做的事情,但我个人总是记录我构建代码的次数。也就是说,我调用make的次数和构建成功的次数 我当前的解决方案 我有一个简单的代码,它把一个文件作为参数,打开它,增加里面的数字,然后覆盖它。当调用make时,首先要编译此代码 紧接着,调用了/increase\u build build.txt,它增加了我调用make来构建库的次数 然后,编译代码并生成lib文件(使用arcq…)。然后,调用/increase\u build libbuild.txt,以增加成功生成的数量。
make
的次数和构建成功的次数
我当前的解决方案
我有一个简单的代码,它把一个文件作为参数,打开它,增加里面的数字,然后覆盖它。当调用make
时,首先要编译此代码
紧接着,调用了/increase\u build build.txt
,它增加了我调用make
来构建库的次数
然后,编译代码并生成lib文件(使用arcq…
)。然后,调用/increase\u build libbuild.txt
,以增加成功生成的数量。最后进行了测试
是我的一个makefile的示例
我为什么担心
在我开始使用版本控制之前,这一直都很有效。似乎没有问题:我是我自己库的唯一作者,我一个接一个地添加特性
不过有一天,我在测试分支和合并(我自己和svn在工作中使用git),所以我在分支中添加了一个特性,并在master中更改了一些内容,然后将两者合并。现在,生成计数文件具有不同的值
问题
问题是,假设在分支时,构建计数是100。然后我在分支中写一些东西,构建计数达到110。我在主分支中写了一些东西,构建计数达到120。当我将两者合并时,我看到一个是110,一个是120(顺便说一下,这是一个冲突)。正确的解决方案是将构建设置为130
但是,我不能(读取我不想)返回到分支开始的提交,并发现它是100,所以我计算100+(110-100)+(120-100)=130!我希望这是自动的
问题
问题很明显:我该怎么做?在使用版本控制时,如何跟踪生成计数(而不是提交计数!)?我不想要一个基于版本控制功能的答案,因为如果我更改版本控制系统,问题会再次出现
我认为可以为每个构建在构建计数文件中添加一行,比如数据和时间。那么build number就是build count文件中的行数。另外,除非我在两个分支上同时得到两个构建,否则合并文件就是这两个分支的并集
我想知道,有没有更好的解决办法?我想要的(构建计数)是否值得付出努力
另外,如果你想知道我为什么要同时考虑构建数量和成功构建数量,那只是个人的问题。我喜欢看我在编写代码时犯的小错误和小错误能得到多少重建
<> > >编辑:我用C和C++编程,所以我的一个解决方案。< p>你的解决方案带有一个构建日志(每行一行)看起来相当聪明。您可以添加执行build do You timstample的机器的IP(或Mac地址),以消除线路重复的风险。但是,根据您的VCS,您可能必须手动合并构建日志文件。 使用git,您可以对其进行配置,这样合并将始终保持两个版本(并最终按日期对行排序,等等) 我无法(阅读我不想)返回到分支开始的提交,并发现它是100,所以我计算。。。我希望这是自动的
肮脏的想法:每个构建都会将字符串添加到版本化文件中(或者根据结果添加到配对通过/失败中的一个),每个分支略有不同。合并分支将需要手动合并此信号文件,其中字符串装饰的差异使此任务更容易。wc-l稍后将统计数字我将发布并接受我自己想法的实现作为答案,因为这似乎是最实际的 这就是解决方案:
- 对于每个生成,向包含以下数据的生成文件添加一行:
- 日期
- 时间
- 随机数
- 每次合并时,保留两个生成文件中的行
- 生成数是生成文件中的行总数
time(NULL)
对srand
进行种子设定,则由于假定两个构建同时进行,因此生成的数字也可能恰好相同。因此,随机数生成器可以使用不同的数字作为种子,例如clock()
或gettimeofday()
的毫秒部分。即使不是随机生成的,这些数字本身也可以代替随机数
如果仍然有两行结束相同,我将应用
更新:
我实现了它,一切正常。最后,我使用了clock\u gettime(clock\u MONOTONIC,…)
并将此函数获得的纳秒作为随机数打印出来。我没有使用clock()
的原因是,由于程序很短,所以运行的分辨率低于clock()
的分辨率,因此我一直得到0
更新:
这是我写的最后一段代码(其中一些部分是从其他地方偷来的!)。您可能需要在某些平台上安装
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef _WIN32
#include <windows.h>
struct timespec
{
long tv_sec;
long tv_nsec;
};
/* Note: I copy-pasted this from internet (https://stackoverflow.com/questions/5404277/porting-clock-gettime-to-windows/5404467#5404467)
* I tweaked it to return nanoseconds instead of microseconds
* It is much more complete than just finding tv_nsec, but I'm keeping it for possible future use. */
LARGE_INTEGER getFILETIMEoffset(void)
{
SYSTEMTIME s;
FILETIME f;
LARGE_INTEGER t;
s.wYear = 1970;
s.wMonth = 1;
s.wDay = 1;
s.wHour = 0;
s.wMinute = 0;
s.wSecond = 0;
s.wMilliseconds = 0;
SystemTimeToFileTime(&s, &f);
t.QuadPart = f.dwHighDateTime;
t.QuadPart <<= 32;
t.QuadPart |= f.dwLowDateTime;
return t;
}
int clock_gettime(int X, struct timespec *tv)
{
LARGE_INTEGER t;
FILETIME f;
double microseconds;
static LARGE_INTEGER offset;
static double frequencyToNanoseconds;
static int initialized = 0;
static BOOL usePerformanceCounter = 0;
if (!initialized)
{
LARGE_INTEGER performanceFrequency;
initialized = 1;
usePerformanceCounter = QueryPerformanceFrequency(&performanceFrequency);
if (usePerformanceCounter)
{
QueryPerformanceCounter(&offset);
frequencyToNanoseconds = (double)performanceFrequency.QuadPart/1000000000.0;
}
else
{
offset = getFILETIMEoffset();
frequencyToNanoseconds = 0.010;
}
}
if (usePerformanceCounter)
QueryPerformanceCounter(&t);
else
{
GetSystemTimeAsFileTime(&f);
t.QuadPart = f.dwHighDateTime;
t.QuadPart <<= 32;
t.QuadPart |= f.dwLowDateTime;
}
t.QuadPart -= offset.QuadPart;
microseconds = (double)t.QuadPart/frequencyToNanoseconds;
t.QuadPart = microseconds;
tv->tv_sec = t.QuadPart/1000000000;
tv->tv_nsec = t.QuadPart%1000000000;
return 0;
}
#ifndef CLOCK_MONOTONIC
#define CLOCK_MONOTONIC 0 /* not used anyway */
#endif
#endif
int main(int argc, char **argv)
{
time_t now_sec;
struct tm *now;
FILE *bout;
struct timespec now_clk;
if (argc < 2)
{
printf("Usage: %s build_file_name\n\n", argv[0]);;
return EXIT_FAILURE;
}
bout = fopen(argv[1], "a");
if (!bout)
{
printf("Could not open file: %s\n\n", argv[1]);
return EXIT_FAILURE;
}
time(&now_sec);
now = gmtime(&now_sec);
fprintf(bout, "%02d/%02d/%04d %02d:%02d:%02d", now->tm_mday, now->tm_mon+1, now->tm_year+1900, now->tm_hour, now->tm_min, now->tm_sec);
clock_gettime(CLOCK_MONOTONIC, &now_clk);
fprintf(bout, " %ld\n", now_clk.tv_nsec);
return EXIT_SUCCESS;
}
/*
*此程序是免费软件:您可以重新发布和/或修改它
*它是根据GNU通用公共许可证的条款发布的
*法国
# I don't know git -- this is all very much pseudocode
# Where did you commit the code you want to build?
source=git://server/path/to/my/branch
# Replace builddir tree with yours
git replace git://server/special/place/build/thisproject with code from $source
cd /tmp
git checkout git://sever/special/place/build/thisproject into new builddir
cd builddir
update local version-controlled file buildnumber+=1
if make
# Build was successful
git commit buildnumber
copy build artefacts to where-ever
endif
cd /tmp
rm -rf /tmp/builddir