博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Mercurial 的hook使用
阅读量:5114 次
发布时间:2019-06-13

本文共 3273 字,大约阅读时间需要 10 分钟。

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 commentscommit: This is run after a new changeset has been created in the local repository. No commentsincoming: 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 commentsoutgoing: This is run after a group of changesets has been transmitted from this repository. No commentsprechangegroup: This is run before starting to bring a group of changesets into the repository. 2 commentsprecommit: Controlling. This is run before starting a commit. 2 commentspreoutgoing: Controlling. This is run before starting to transmit a group of changesets from this repository. No commentspretag: Controlling. This is run before creating a tag. No commentspretxnchangegroup: 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 commentspretxncommit: 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 commentpreupdate: Controlling. This is run before starting an update or merge of the working directory. One commenttag: This is run after a tag is created. No commentsupdate: 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 redef 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 
.
-branch)\n')return Truereturn 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

转载于:https://www.cnblogs.com/ZhYQ-Note/p/5556769.html

你可能感兴趣的文章
Screening technology proved cost effective deal
查看>>
Thrift Expected protocol id ffffff82 but got 0
查看>>
【2.2】创建博客文章模型
查看>>
Jsp抓取页面内容
查看>>
大三上学期软件工程作业之点餐系统(网页版)的一些心得
查看>>
可选参数的函数还可以这样设计!
查看>>
Java语言概述
查看>>
关于BOM知识的整理
查看>>
使用word发布博客
查看>>
面向对象的小demo
查看>>
微服务之初了解(一)
查看>>
GDOI DAY1游记
查看>>
收集WebDriver的执行命令和参数信息
查看>>
数据结构与算法(三)-线性表之静态链表
查看>>
mac下的mysql报错:ERROR 1045(28000)和ERROR 2002 (HY000)的解决办法
查看>>
MyBaits动态sql语句
查看>>
HDU4405(期望DP)
查看>>
拉格朗日乘子法 那些年学过的高数
查看>>
vs code 的便捷使用
查看>>
Spring MVC @ResponseBody返回中文字符串乱码问题
查看>>