Reload hgrc before notify hook call ?

Yannick CHARLES yannick.charles at gmail.com
Wed Dec 5 19:08:32 UTC 2012


Good evening again,

I found the solution to my problem: in order for the hook script to reflect
the changes in notify.py, a restart of apache on the server was needed (I
guess it's because the hook is called after a http push).

Then I was able to do what I wanted with the following patch to notify.py:
______________________________

--- notify_old.py    2012-12-05 12:59:12.900378729 +0100
+++ notify_mod.py    2012-12-05 19:54:09.341389069 +0100
@@ -54,6 +54,9 @@

 Notifications content can be tweaked with the following configuration
entries:

+notify.testfile
+  File to read to get the most recent value of ``notify.test``.
+
 notify.test
   If ``True``, print messages to stdout instead of sending them. Default:
True.

@@ -81,6 +84,9 @@
 notify.style
   Style file to use when formatting emails.

+notify.templatefile
+  File to read to get the most recent template.
+
 notify.template
   Template to use when formatting emails.

@@ -171,12 +177,18 @@
         self.root = self.strip(self.repo.root)
         self.domain = self.ui.config('notify', 'domain')
         self.mbox = self.ui.config('notify', 'mbox')
+        testfile = self.ui.config('notify', 'testfile')
+        if testfile:
+            self.ui.readconfig(testfile, sections=['notify'])
         self.test = self.ui.configbool('notify', 'test', True)
         self.charsets = mail._charsets(self.ui)
         self.subs = self.subscribers()
         self.merge = self.ui.configbool('notify', 'merge', True)

         mapfile = self.ui.config('notify', 'style')
+        templatefile = self.ui.config('notify', 'templatefile')
+        if templatefile:
+            self.ui.readconfig(templatefile, sections=['notify'])
         template = (self.ui.config('notify', hooktype) or
                     self.ui.config('notify', 'template'))
         self.t = cmdutil.changeset_templater(self.ui, self.repo,
________________________________________

However that wasn't easy to figure out, not having a clue about mercurial's
internals and not knowing much about python. I managed to found some
reference about ui.readconfig in some doxygen report, then looked a bit in
the source... and crossing with what I was seeing in notify.py.

Maybe it would be useful to improve available API information ?

Best regards !
Yannick

2012/12/5 Yannick CHARLES <yannick.charles at gmail.com>

> Thanks for your answers. :)
>
> I've tried to look into notify.py source code, and to find information on
> Mercurial API. I found ui.readconfig() that might do the job.
> Regarding the API, I found the page
> http://mercurial.selenic.com/wiki/MercurialApi - is there a more complete
> documentation somewhere ?
>
> Regarding notify source code, I tried to modify the file located at
> /usr/share/pyshared/hgext/notify.py and it doesn't seem to reflect the
> changes I make.
> Is there something particular I need to do, or do I miss some point (I'm a
> python newbie, sorry).
>
> Yannick
>
>
> 2012/12/4 Matt Mackall <mpm at selenic.com>
>
>> On Tue, 2012-12-04 at 13:47 +0100, Yannick CHARLES wrote:
>> > Hello to everybody,
>> >
>> > I have the following hgrc in a versionned patch queue, on a remote
>> > server where I can push over http:
>> > ------
>> > #
>> > # [web] section goes here
>> > #
>> >
>> > [hooks]
>> > changegroup.00updatefiles = hg update
>> > changegroup.01autobuild_patch = bash ../patch_chgrouphook.sh Yann
>> >
>> > # Include notify parameters
>> > %include /var/hg/repos/test-syst/.hg/notifypatches.rc
>> >
>> > [hooks]
>> > # Here for testing purposes
>> > changegroup.02upcf = hg showconfig
>> >
>> > # Include notify hook
>> > %include /var/hg/repos/test-syst/.hg/notifyphook.rc
>> > ------
>> >
>> > /var/hg/repos/test-syst/.hg/notifyphook.rc normally contains the
>> > following lines:
>> > ------
>> > [hooks]
>> > changegroup.03notify = python:hgext.notify.hook
>> > ------
>> >
>> > Hook 01 rebuilds the project's output files, but also modify notify's
>> > template. This modification is reflected by hook 02 where I see the new
>> > template.
>> > However, in hook 03, notify still uses the old template.
>> >
>> > I guess this is because though hooks are run in order, hgrc is only
>> > parsed once when I push on the repo (and parsed again to run
>> > showconfig), so notify is passed the values present in hgrc at the
>> > beginning of the changegroup event.
>> > Is my interpretation correct?
>> >
>> > My second problem is that in some cases, I wouldn't like notify to send
>> > e-mails (e.g. the patch queue is empty). To achieve this I tried in the
>> > same way to have the bash script called by the 01 hook to modify
>> > notifyphook.rc into an empty file, but I have the same problem (i.e. the
>> > file used is the previous one).
>> >
>> >
>> > So starting from this, I have three questions:
>> > -Is there a way to somehow reload hgrc before calling the notify hook,
>> > or to call it with the updated parameters (if so, it could fix the 2nd
>> > pb as well, as I would set notify.test to true)?
>>
>> No.
>>
>> > -Would it be possible to call the python notify hook directly from the
>> > bash script from hook 01?
>>
>> No.
>>
>> > -Is it possible to run a hook only under certain conditions?
>>
>> No.
>>
>> > Or maybe I'm looking at the wrong direction, and it would be better to
>> > rewrite a mail-sending procedure from scratch in the form of a bash
>> > script for example?
>>
>> You could do that. Or you could make (fairly minor) changes to a private
>> copy of notify.py.
>>
>> --
>> Mathematics is the supreme nostalgia of our time.
>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial/attachments/20121205/45171d44/attachment-0002.html>


More information about the Mercurial mailing list