How can I monitor a specific file for changes in Mercurial?

送分小仙女□ 提交于 2019-12-11 06:29:07

问题


I have set up a remote Mercurial (Hg) repository that holds a large Java project. I would like to monitor any changes done to the project's pom file and receive e-mails when changes were made to the pom.

I would like to exclude all other file changes from notifications as I am only interested in monitoring any possible changes in dependencies (hence the POM). Is there any Mercurial Extension or workaround using Jenkins to subscribe to the change history for one individual file inside a Mercurial repo?


回答1:


The notify extension sends email on repo changes.

The Change Context (look in section 6) gives you a way to iterate over the files in the changeset.

Putting these two things together in a custom hook should be fairly straightforward. Look through the context and only send email if your special file is mentioned.




回答2:


@Ed.ward

I recently had to do this (combine the notify extension with the change context) to only notify if certain files changed. In order to call the notify hook from your own hook, you need to import hgext and then call hgext.notify.hook. My python working example:

import re, traceback
import hgext
def check_changegroup(ui, repo, hooktype, node=None, source=None, **kwargs):
    ui.note("Checking for files in %s with path: %s\n" % (repo.__class__.__name__, repo.root))
    file_match = ".*base.*" #ui.config('monitor_files', 'file_match')
    ui.note("file_match: %s\n" % file_match)
    file_match_re = re.compile(file_match, re.I)
    monitored_file_changed = False
    for rev in xrange(repo[node].rev(), len(repo)):
        changectx = repo[rev]       
        for f in changectx.files():
            if file_match_re.match(f):
                ui.note("  matched: %s\n" % f)
                monitored_file_changed = True
        if monitored_file_changed:
            ui.note("rev: %s from user: %s has changes on monitored files\n" % (rev, changectx.user()))
    if monitored_file_changed:
        ui.note("calling notify hook\n")
        try:
            hgext.notify.hook(ui, repo, hooktype, node, source)
        except Exception as exc:
            ui.warn(('%s error calling notify hook: %s\n') % (exc.__class__.__name__, exc))
            traceback.print_exc()
            raise


来源:https://stackoverflow.com/questions/10011288/how-can-i-monitor-a-specific-file-for-changes-in-mercurial

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!