Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否可以从预提交钩子中找到mercurial存储库的最近推送时间?_Mercurial_Pre Commit Hook - Fatal编程技术网

是否可以从预提交钩子中找到mercurial存储库的最近推送时间?

是否可以从预提交钩子中找到mercurial存储库的最近推送时间?,mercurial,pre-commit-hook,Mercurial,Pre Commit Hook,我有一个Mercurial存储库,我正在尝试创建一个提交钩子,如果以前的最新推送在过去15分钟内发生,它可以拒绝新的传入推送(作为节流的一种形式,因此我们可以确保我们的自动测试在其他人到达可能出现故障的代码顶部之前有时间完成,而其他人现在可能到达出现双重故障的代码) 因此,我将服务器端hgrc文件设置为: [hooks] prechangegroup.throttlehook = python:path/to/throttlescript.py:hook 我使用prechangegroup钩子

我有一个Mercurial存储库,我正在尝试创建一个提交钩子,如果以前的最新推送在过去15分钟内发生,它可以拒绝新的传入推送(作为节流的一种形式,因此我们可以确保我们的自动测试在其他人到达可能出现故障的代码顶部之前有时间完成,而其他人现在可能到达出现双重故障的代码)

因此,我将服务器端hgrc文件设置为:

[hooks]
prechangegroup.throttlehook = python:path/to/throttlescript.py:hook
我使用prechangegroup钩子,因为它允许我访问存储库,因为它不需要传入的push提交

钩子可以工作,因为脚本的代码可以运行,如果返回非零返回代码,则可以拒绝传入的推送

我遇到的困难是获取最近推送的时间戳。在throttlescript.py中,我有以下内容:

import time
def hook(ui, repo, **kwargs):
    difference = time.time() - repo['tip'].date()[0] # this should be the difference between the current time and the most recent push
    if difference < 900:
        print "You are pushing too soon after the most recent push. Please try again later."
        return 1
    return 0
导入时间
def挂钩(用户界面、回购、**kwargs):
差异=时间.time()-repo['tip'].date()[0]#这应该是当前时间和最近推送之间的差异
如果差值小于900:
打印“您在最近一次推送后推送得太快。请稍后再试。”
返回1
返回0
但是
repo['tip'].date()[0]
似乎是最近提交的时间戳,它可能在推送到my canonical存储库之前很久就发生了,因此它可能不能被信任为最近推送的时间戳


是否还有其他地方可以找到推送的时间戳,而不是提交的时间戳?我可以使用存储库的.hg文件夹中某个文件的上次修改时间吗?

Mercurial不跟踪推送和拉送,只跟踪它们带来的更改集。Mozilla人员编写了一个名为“pushlog”的扩展,记录所有推送和拉送操作拉到原木,很难,我不认为它被广泛使用

如果你想稍微放松一下,你可以在
.hg/store/00changelog.i
文件中检查上次修改的时间,每次推送成功后都会写入该文件

在bash中,您可以使用find轻松完成此任务:

#!/bin/bash
if test -z $(find .hg/store/00changelog.i -newerct '15 minutes ago') ; then
    exit 0
fi
echo "You are pushing too soon after the most recent push. Please try again later."
exit 1

我预测你只会激怒你的同事。:)

好吧,幸运的是,我是为Mozilla基础设施写这篇文章的!;)酷。如果他们还在使用它,pushlog就是一个文本文件。检查它的lastmodified time可能仍然是最简单的,这使得上面的解决方案最简单。