我需要在服务器端挂钩中获取已更改文件的列表。例子:
Local commit 1:
M test.txt
M test2.txt
Local commit 2:
M test.txt
A test3.txt
Run Code Online (Sandbox Code Playgroud)
两个提交都被推送到服务器(裸仓库)。我需要遍历文件列表并通过 curl 在其他地方发布每个文件:
M test.txt
M test2.txt
A test3.txt
Run Code Online (Sandbox Code Playgroud)
我正在努力寻找实现这一目标的文档。我知道这些修订是针对标准输入的。我如何实际遍历推送的文件,并引用它们进行 curl 上传(这似乎很困难,因为它是一个裸仓库)?
#!/bin/bash
while read oldrev newrev refname; do
echo $oldrev
echo $newrev
echo $refname
done < "${1:-/dev/stdin}"
Run Code Online (Sandbox Code Playgroud) public class UniqueNameAttribute : ValidationAttribute
{
private const string UniqueNameViolationMessage = "This name is already taken. Please select another.";
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
//return somerepo.IsUniqueName(name)
//how do I get access to repo here? Tried DI with autofac but it came out as null
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用依赖注入将存储库注入我的Web API.但是,似乎我无法注入ValidationAttribute.如果我尝试注入,它会出现null.我正在使用Autofac进行DI.有没有其他方式可以访问我的回购?
请注意,我只使用Web API,而不是MVC,所以我不能使用MVC DependencyResolver.
builder.RegisterType<MyRepository>().As<IMyRepository>().InstancePerRequest();
var container = builder.Build();
GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver((IContainer)container); ;
Run Code Online (Sandbox Code Playgroud) 我很难弄清楚 select() 是如何处理 UNIX 中的管道的。我已经多次扫描手册页,但我并不完全理解给定的定义。
通过阅读手册页,我的印象是 select() 会使系统等待,直到给定的文件描述符之一可以在不阻塞的情况下从管道读取(在我的情况下)。
这是我的一些大纲代码[编辑]:
int size, size2;
fd_set rfds;
struct timeval tv;
char buffer[100];
char buffer2[100];
int retval;
while(1)
{
FD_ZERO(&rfds);
FD_SET(fd[0], &rfds);
FD_SET(fd2[0], &rfds);
tv.tv_sec = 2;
tv.tv_usec = 0;
retval = select(2, &rfds, NULL, NULL, &tv); //2 seconds before timeout
if(retval == -1)
perror("Select failed.\n");
else if(retval)
{
size = read(fd[0], buffer, sizeof(buffer));
if(size > 0)
printf("Parent received from even: %s\n", buffer);
size2 = read(fd2[READ], buffer2, sizeof(buffer2));
if(size2 > 0)
printf("Parent received from …Run Code Online (Sandbox Code Playgroud)