1、

Handling repository events with hooks
可以通过Mercurial版本管理工具提供的hooks机制来处理repo的各种事件,从而实现对Mercurial的扩展,实现我们的特定需求。

2、
常用的hooks event事件:
摘自:http://hgbook.red-bean.com/read/handling-repository-events-with-hooks.html#sec:hook:precommit

changegroup: This is run after a group of changesets has been brought into the repository from elsewhere. 5 comments

commit: This is run after a new changeset has been created in the local repository. No comments

incoming: This is run once for each new changeset that is brought into the repository from elsewhere. Notice the difference from changegroup, which is run once per group of changesets brought in. No comments

outgoing: This is run after a group of changesets has been transmitted from this repository. No comments

prechangegroup: This is run before starting to bring a group of changesets into the repository. 2 comments

precommit: Controlling. This is run before starting a commit. 2 comments

preoutgoing: Controlling. This is run before starting to transmit a group of changesets from this repository. No comments

pretag: Controlling. This is run before creating a tag. No comments

pretxnchangegroup: Controlling. This is run after a group of changesets has been brought into the local repository from another, but before the transaction completes that will make the changes permanent in the repository. No comments

pretxncommit: Controlling. This is run after a new changeset has been created in the local repository, but before the transaction completes that will make it permanent. One comment

preupdate: Controlling. This is run before starting an update or merge of the working directory. One comment

tag: This is run after a tag is created. No comments

update: This is run after an update or merge of the working directory has finished. No comments

3、

hook配置:
可以修改本地仓库下面.hg/hgrc配置文件,语法规则:
The syntax for Python hooks is as follows:

hookname = python:modulename.submodule.callable
hookname = python:/path/to/python/module.py:callable
例:
[hooks]
precommit = python:.hg/signoff.py:sign_commit_message

4、函数参数:
all hooks will take ui, repo,hooktype -- that's a very common pattern in Mercurial code (core, extensions, hooks, whatever)
例:我们一般可以这样定义函数:

import re

def precommit_badbranch(ui, repo, **kwargs):
branch = repo[None].branch()
branch_re = re.compile(r'\d+\.\d+-branch$')
if not branch_re.match(branch):
ui.warn('invalid branch name %r (use <major>.<minor>-branch)\n')
return True
return False

5、返回值:
Hooks can be implemented as either external programs, or internal python calls. The meaning of the return value in both cases is based on the convention for external executables; in other words, a value of 0 means "success". For hooks implemented in python this can be a bit misleading, since it means you return "False" to indicate success and "True" (or throw an exception) to indicate failure.

return True 表明失败, 则此命令执行会失败
return False表明成功,此命令可以执行

6、
The Mercurial API
在写hook的时候,我们可以使用很多Mercurial提供的api,具体参见:
https://www.mercurial-scm.org/wiki/MercurialApi

参考:
http://hgbook.red-bean.com/ --重要
https://www.mercurial-scm.org/wiki/HookExamples
https://www.mercurial-scm.org/wiki/MercurialApi
https://www.mercurial-scm.org/wiki/Hook
https://selenic.com/hg/help/hgrc

Mercurial 的hook使用的更多相关文章

  1. Mercurial (hg) Hook : PHP Syntax Check , hg 代码检测 钩子

    用百度搜了一遍hg的hook教程,发现真的是太少了.公司目前正要用到这个,正好本人负责,So. 百度是个坑,少有的几篇文章,再加上善于发现的眼睛,发现TortoiseHg的UI操作都会在控制台显示动作 ...

  2. svnserver hook python

    在使用中可能会遇到的错误排除 :1.Error: svn: 解析"D:\www\test"出错,或svn: E020024: Error resolving case of 'D: ...

  3. Android Hook技术

    原文:http://blog.csdn.net/u011068702/article/details/53208825 附:Android Hook 全面入侵监听器 第一步.先爆项目demo照片,代码 ...

  4. Frida HOOK微信实现骰子作弊

    由于微信摇骰子的功能在本地进行随机后在发送,所以存在可以hook掉判断骰子数的方法进行修改作弊. 1.frida实现hook java层函数1)写个用来测试的demo,当我们点击按钮的时候会弹出窗口显 ...

  5. java的关闭钩子(Shutdown Hook)

    Runtime.getRuntime().addShutdownHook(shutdownHook);    这个方法的含义说明:        这个方法的意思就是在jvm中增加一个关闭的钩子,当jv ...

  6. IDT HOOK思路整理

    IDT(中断描述符表)分为IRQ(真正的硬件中断)和软件中断(又叫异常). HOOK的思路为,替换键盘中断处理的函数地址为自己的函数地址.这样在键盘驱动和过滤驱动之前就可以截获键盘输入. 思路确定之后 ...

  7. [解决]Mercurial HTTP Error 500: Access is denied on 00changelog.i

    总之,用户对仓库目录要有写权限 00changelog, access is denied, hg, http error 500, mercurial, permissions, push Merc ...

  8. Android Hook 借助Xposed

    主要就是使用到了Xposed中的两个比较重要的方法,handleLoadPackage获取包加载时候的回调并拿到其对应的classLoader:findAndHookMethod对指定类的方法进行Ho ...

  9. iOS App 无代码入侵的方法hook

    继续Objective-C runtime的研究 最近公司项目在做用户行为分析 于是App端在某些页面切换,交互操作的时候需要给统计系统发送一条消息 在几十个Controller 的项目里,一个一个地 ...

随机推荐

  1. WC2018 文艺汇演《退役的你》

    视频网址:https://www.bilibili.com/video/av19333297 谨以此歌献给那些曾与我们并肩前行的退役 OIer 填词 & 视频:Menci 演唱:wxh0109 ...

  2. BZOJ1040: [ZJOI2008]骑士(奇环树,DP)

    题目: 1040: [ZJOI2008]骑士 解析: 假设骑士\(u\)讨厌骑士\(v\),我们在\(u\),\(v\)之间连一条边,这样我们就得到了一个奇环树(奇环森林),既然是一颗奇环树,我们就先 ...

  3. python爬虫---详解爬虫分类,HTTP和HTTPS的区别,证书加密,反爬机制和反反爬策略,requests模块的使用,常见的问题

    python爬虫---详解爬虫分类,HTTP和HTTPS的区别,证书加密,反爬机制和反反爬策略,requests模块的使用,常见的问题 一丶爬虫概述       通过编写程序'模拟浏览器'上网,然后通 ...

  4. pat 1039到底买不买

    小红想买些珠子做一串自己喜欢的珠串.卖珠子的摊主有很多串五颜六色的珠串,但是不肯把任何一串拆散了卖.于是小红要你帮忙判断一下,某串珠子里是否包含了全部自己想要的珠子?如果是,那么告诉她有多少多余的珠子 ...

  5. Jest单元测试进阶

    Jest 命令行窗口中的指令 在学习Jest单元测试入门的时候,给Jest命令提供了一个参数 --watchAll, 让它监听测试文件或测试文件引入的文件的变化,从而时时进行测试.但这样做也带来一个问 ...

  6. Pandas 之 Series / DataFrame 初识

    import numpy as np import pandas as pd Pandas will be a major tool of interest throughout(贯穿) much o ...

  7. MySQL同步故障:" Slave_SQL_Running:No" 两种解决办法

    进入slave服务器,运行: mysql> show slave status\G Relay_Log_File: localhost-relay-bin.000535 Relay_Log_Po ...

  8. Netbackup常用命令--bprestore

    bprestore bprestore – 从 NetBackup 服务器还原文件 大纲 bprestore [-A | -B | -rb] [-K] [-l | -H | -y] [-r] [-T] ...

  9. input事件在进行模糊搜索时,用到的即时监测input的值变化的方法(即时搜索的input和propertychange方法)

    做搜索功能的时候,经常遇到输入框检查的需求,最常见的是即时搜索,今天好好小结一下. 即时搜索的方案: (1)change事件    触发事件必须满足两个条件: a)当前对象属性改变,并且是由键盘或鼠标 ...

  10. 源码查看Thread.interrupted()和Thread.currentThread().isInterrupted()区别

    JAVA线程状态.线程START方法源码.多线程.JAVA线程池.如何停止一个线程等多线程问题 这两个方法有点容易记混,这里就记录一下源码. Thread.interrupted()和Thread.c ...