Mercurial > hgbook
comparison en/ch10-hook.xml @ 680:8366882f67f2
Fix up more formatting goop
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Wed, 18 Mar 2009 00:00:58 -0700 |
parents | 13513d2a128d |
children | d0160b0b1a9e |
comparison
equal
deleted
inserted
replaced
679:80928ea6e7ae | 680:8366882f67f2 |
---|---|
113 </para> | 113 </para> |
114 | 114 |
115 <para>In some cases, you may be exposed to hooks that you did | 115 <para>In some cases, you may be exposed to hooks that you did |
116 not install yourself. If you work with Mercurial on an | 116 not install yourself. If you work with Mercurial on an |
117 unfamiliar system, Mercurial will run hooks defined in that | 117 unfamiliar system, Mercurial will run hooks defined in that |
118 system's global <filename role="special"> /.hgrc</filename>\ | 118 system's global <filename role="special">~/.hgrc</filename> |
119 file. | 119 file. |
120 </para> | 120 </para> |
121 | 121 |
122 <para>If you are working with a repository owned by another | 122 <para>If you are working with a repository owned by another |
123 user, Mercurial can run hooks defined in that user's | 123 user, Mercurial can run hooks defined in that user's |
173 </para> | 173 </para> |
174 | 174 |
175 <para>In a corporate intranet, this is somewhat easier to | 175 <para>In a corporate intranet, this is somewhat easier to |
176 control, as you can for example provide a | 176 control, as you can for example provide a |
177 <quote>standard</quote> installation of Mercurial on an NFS | 177 <quote>standard</quote> installation of Mercurial on an NFS |
178 filesystem, and use a site-wide <filename role="special"> | 178 filesystem, and use a site-wide <filename role="special">~/.hgrc</filename> file to define hooks that all users will |
179 /.hgrc</filename>\ file to define hooks that all users will | |
180 see. However, this too has its limits; see below. | 179 see. However, this too has its limits; see below. |
181 </para> | 180 </para> |
182 | 181 |
183 </sect2> | 182 </sect2> |
184 <sect2> | 183 <sect2> |
188 redefining the hook. You can disable it by setting its value | 187 redefining the hook. You can disable it by setting its value |
189 to the empty string, or change its behaviour as you wish. | 188 to the empty string, or change its behaviour as you wish. |
190 </para> | 189 </para> |
191 | 190 |
192 <para>If you deploy a system- or site-wide <filename | 191 <para>If you deploy a system- or site-wide <filename |
193 role="special"> /.hgrc</filename>\ file that defines some | 192 role="special">~/.hgrc</filename> file that defines some |
194 hooks, you should thus understand that your users can disable | 193 hooks, you should thus understand that your users can disable |
195 or override those hooks. | 194 or override those hooks. |
196 </para> | 195 </para> |
197 | 196 |
198 </sect2> | 197 </sect2> |
201 | 200 |
202 <para>Sometimes you may want to enforce a policy that you do not | 201 <para>Sometimes you may want to enforce a policy that you do not |
203 want others to be able to work around. For example, you may | 202 want others to be able to work around. For example, you may |
204 have a requirement that every changeset must pass a rigorous | 203 have a requirement that every changeset must pass a rigorous |
205 set of tests. Defining this requirement via a hook in a | 204 set of tests. Defining this requirement via a hook in a |
206 site-wide <filename role="special"> /.hgrc</filename>\ won't | 205 site-wide <filename role="special">~/.hgrc</filename> won't |
207 work for remote users on laptops, and of course local users | 206 work for remote users on laptops, and of course local users |
208 can subvert it at will by overriding the hook. | 207 can subvert it at will by overriding the hook. |
209 </para> | 208 </para> |
210 | 209 |
211 <para>Instead, you can set up your policies for use of Mercurial | 210 <para>Instead, you can set up your policies for use of Mercurial |
357 | 356 |
358 &interaction.hook.simple.init; | 357 &interaction.hook.simple.init; |
359 | 358 |
360 <para>You add an entry to the <literal | 359 <para>You add an entry to the <literal |
361 role="rc-hooks">hooks</literal> section of your <filename | 360 role="rc-hooks">hooks</literal> section of your <filename |
362 role="special"> /.hgrc</filename>. On the left is the name of | 361 role="special">~/.hgrc</filename>. On the left is the name of |
363 the event to trigger on; on the right is the action to take. As | 362 the event to trigger on; on the right is the action to take. As |
364 you can see, you can run an arbitrary shell command in a hook. | 363 you can see, you can run an arbitrary shell command in a hook. |
365 Mercurial passes extra information to the hook using environment | 364 Mercurial passes extra information to the hook using environment |
366 variables (look for <envar>HG_NODE</envar> in the example). | 365 variables (look for <envar>HG_NODE</envar> in the example). |
367 </para> | 366 </para> |
531 </sect2> | 530 </sect2> |
532 <sect2> | 531 <sect2> |
533 <title>Writing an external hook</title> | 532 <title>Writing an external hook</title> |
534 | 533 |
535 <para>When you define an external hook in your <filename | 534 <para>When you define an external hook in your <filename |
536 role="special"> /.hgrc</filename>\ and the hook is run, its | 535 role="special">~/.hgrc</filename> and the hook is run, its |
537 value is passed to your shell, which interprets it. This | 536 value is passed to your shell, which interprets it. This |
538 means that you can use normal shell constructs in the body of | 537 means that you can use normal shell constructs in the body of |
539 the hook. | 538 the hook. |
540 </para> | 539 </para> |
541 | 540 |
559 | 558 |
560 </sect2> | 559 </sect2> |
561 <sect2> | 560 <sect2> |
562 <title>Telling Mercurial to use an in-process hook</title> | 561 <title>Telling Mercurial to use an in-process hook</title> |
563 | 562 |
564 <para>The <filename role="special"> /.hgrc</filename>\ syntax | 563 <para>The <filename role="special">~/.hgrc</filename> syntax |
565 for defining an in-process hook is slightly different than for | 564 for defining an in-process hook is slightly different than for |
566 an executable hook. The value of the hook must start with the | 565 an executable hook. The value of the hook must start with the |
567 text <quote><literal>python:</literal></quote>, and continue | 566 text <quote><literal>python:</literal></quote>, and continue |
568 with the fully-qualified name of a callable object to use as | 567 with the fully-qualified name of a callable object to use as |
569 the hook's value. | 568 the hook's value. |
573 when a hook is run. So long as you have the module name and | 572 when a hook is run. So long as you have the module name and |
574 <envar>PYTHONPATH</envar> right, it should <quote>just | 573 <envar>PYTHONPATH</envar> right, it should <quote>just |
575 work</quote>. | 574 work</quote>. |
576 </para> | 575 </para> |
577 | 576 |
578 <para>The following <filename role="special"> /.hgrc</filename>\ | 577 <para>The following <filename role="special">~/.hgrc</filename> |
579 example snippet illustrates the syntax and meaning of the | 578 example snippet illustrates the syntax and meaning of the |
580 notions we just described. | 579 notions we just described. |
581 </para> | 580 </para> |
582 <programlisting>[hooks] commit.example = | 581 <programlisting>[hooks] |
583 python:mymodule.submodule.myhook</programlisting> | 582 commit.example = python:mymodule.submodule.myhook</programlisting> |
584 <para>When Mercurial runs the <literal>commit.example</literal> | 583 <para>When Mercurial runs the <literal>commit.example</literal> |
585 hook, it imports <literal>mymodule.submodule</literal>, looks | 584 hook, it imports <literal>mymodule.submodule</literal>, looks |
586 for the callable object named <literal>myhook</literal>, and | 585 for the callable object named <literal>myhook</literal>, and |
587 calls it. | 586 calls it. |
588 </para> | 587 </para> |
593 | 592 |
594 <para>The simplest in-process hook does nothing, but illustrates | 593 <para>The simplest in-process hook does nothing, but illustrates |
595 the basic shape of the hook API: | 594 the basic shape of the hook API: |
596 </para> | 595 </para> |
597 <programlisting>def myhook(ui, repo, **kwargs): | 596 <programlisting>def myhook(ui, repo, **kwargs): |
598 pass</programlisting> | 597 pass</programlisting> |
599 <para>The first argument to a Python hook is always a <literal | 598 <para>The first argument to a Python hook is always a <literal |
600 role="py-mod-mercurial.ui">ui</literal> object. The second | 599 role="py-mod-mercurial.ui">ui</literal> object. The second |
601 is a repository object; at the moment, it is always an | 600 is a repository object; at the moment, it is always an |
602 instance of <literal | 601 instance of <literal |
603 role="py-mod-mercurial.localrepo">localrepository</literal>. | 602 role="py-mod-mercurial.localrepo">localrepository</literal>. |
743 <literal role="hook">pretxnchangegroup</literal> hook. This | 742 <literal role="hook">pretxnchangegroup</literal> hook. This |
744 lets it see which files are modified by each incoming | 743 lets it see which files are modified by each incoming |
745 changeset, and roll back a group of changesets if they | 744 changeset, and roll back a group of changesets if they |
746 modify <quote>forbidden</quote> files. Example: | 745 modify <quote>forbidden</quote> files. Example: |
747 </para> | 746 </para> |
748 <programlisting>[hooks] pretxnchangegroup.acl = | 747 <programlisting>[hooks] |
749 python:hgext.acl.hook</programlisting> | 748 pretxnchangegroup.acl = python:hgext.acl.hook</programlisting> |
750 | 749 |
751 <para>The <literal role="hg-ext">acl</literal> extension is | 750 <para>The <literal role="hg-ext">acl</literal> extension is |
752 configured using three sections. | 751 configured using three sections. |
753 </para> | 752 </para> |
754 | 753 |
811 <filename class="directory">docs</filename> subtree of the | 810 <filename class="directory">docs</filename> subtree of the |
812 repository, while <literal>intern</literal> can push changes | 811 repository, while <literal>intern</literal> can push changes |
813 to any file or directory except <filename | 812 to any file or directory except <filename |
814 class="directory">source/sensitive</filename>. | 813 class="directory">source/sensitive</filename>. |
815 </para> | 814 </para> |
816 <programlisting>[acl.allow] docs/** = docwriter [acl.deny] | 815 <programlisting>[acl.allow] |
817 source/sensitive/** = intern</programlisting> | 816 docs/** = docwriter |
817 [acl.deny] | |
818 source/sensitive/** = intern</programlisting> | |
818 | 819 |
819 </sect3> | 820 </sect3> |
820 <sect3> | 821 <sect3> |
821 <title>Testing and troubleshooting</title> | 822 <title>Testing and troubleshooting</title> |
822 | 823 |
825 debugging output enabled. Since you'll probably be running | 826 debugging output enabled. Since you'll probably be running |
826 it on a server where it's not convenient (or sometimes | 827 it on a server where it's not convenient (or sometimes |
827 possible) to pass in the <option | 828 possible) to pass in the <option |
828 role="hg-opt-global">--debug</option> option, don't forget | 829 role="hg-opt-global">--debug</option> option, don't forget |
829 that you can enable debugging output in your <filename | 830 that you can enable debugging output in your <filename |
830 role="special"> /.hgrc</filename>: | 831 role="special">~/.hgrc</filename>: |
831 </para> | 832 </para> |
832 <programlisting>[ui] debug = true</programlisting> | 833 <programlisting>[ui] |
834 debug = true</programlisting> | |
833 <para>With this enabled, the <literal | 835 <para>With this enabled, the <literal |
834 role="hg-ext">acl</literal> hook will print enough | 836 role="hg-ext">acl</literal> hook will print enough |
835 information to let you figure out why it is allowing or | 837 information to let you figure out why it is allowing or |
836 forbidding pushes from specific users. | 838 forbidding pushes from specific users. |
837 </para> | 839 </para> |
891 <sect3 id="sec:hook:bugzilla:config"> | 893 <sect3 id="sec:hook:bugzilla:config"> |
892 <title>Configuring the <literal role="hook">bugzilla</literal> | 894 <title>Configuring the <literal role="hook">bugzilla</literal> |
893 hook</title> | 895 hook</title> |
894 | 896 |
895 <para>You should configure this hook in your server's | 897 <para>You should configure this hook in your server's |
896 <filename role="special"> /.hgrc</filename>\ as an <literal | 898 <filename role="special">~/.hgrc</filename> as an <literal |
897 role="hook">incoming</literal> hook, for example as | 899 role="hook">incoming</literal> hook, for example as |
898 follows: | 900 follows: |
899 </para> | 901 </para> |
900 <programlisting>[hooks] incoming.bugzilla = | 902 <programlisting>[hooks] |
901 python:hgext.bugzilla.hook</programlisting> | 903 incoming.bugzilla = python:hgext.bugzilla.hook</programlisting> |
902 | 904 |
903 <para>Because of the specialised nature of this hook, and | 905 <para>Because of the specialised nature of this hook, and |
904 because Bugzilla was not written with this kind of | 906 because Bugzilla was not written with this kind of |
905 integration in mind, configuring this hook is a somewhat | 907 integration in mind, configuring this hook is a somewhat |
906 involved process. | 908 involved process. |
913 <citation>web:mysql-python</citation>. | 915 <citation>web:mysql-python</citation>. |
914 </para> | 916 </para> |
915 | 917 |
916 <para>Configuration information for this hook lives in the | 918 <para>Configuration information for this hook lives in the |
917 <literal role="rc-bugzilla">bugzilla</literal> section of | 919 <literal role="rc-bugzilla">bugzilla</literal> section of |
918 your <filename role="special"> /.hgrc</filename>. | 920 your <filename role="special">~/.hgrc</filename>. |
919 </para> | 921 </para> |
920 <itemizedlist> | 922 <itemizedlist> |
921 <listitem><para><envar | 923 <listitem><para><envar |
922 role="rc-item-bugzilla">version</envar>: The version | 924 role="rc-item-bugzilla">version</envar>: The version |
923 of Bugzilla installed on the server. The database | 925 of Bugzilla installed on the server. The database |
948 <listitem><para><envar | 950 <listitem><para><envar |
949 role="rc-item-bugzilla">password</envar>: The MySQL | 951 role="rc-item-bugzilla">password</envar>: The MySQL |
950 password for the user you configured above. This is | 952 password for the user you configured above. This is |
951 stored as plain text, so you should make sure that | 953 stored as plain text, so you should make sure that |
952 unauthorised users cannot read the <filename | 954 unauthorised users cannot read the <filename |
953 role="special"> /.hgrc</filename>\ file where you | 955 role="special">~/.hgrc</filename> file where you |
954 store this information. | 956 store this information. |
955 </para> | 957 </para> |
956 </listitem> | 958 </listitem> |
957 <listitem><para><envar role="rc-item-bugzilla">db</envar>: | 959 <listitem><para><envar role="rc-item-bugzilla">db</envar>: |
958 The name of the Bugzilla database on the MySQL server. | 960 The name of the Bugzilla database on the MySQL server. |
1003 <para>Each item in the <literal | 1005 <para>Each item in the <literal |
1004 role="rc-usermap">usermap</literal> section contains an | 1006 role="rc-usermap">usermap</literal> section contains an |
1005 email address on the left, and a Bugzilla user name on the | 1007 email address on the left, and a Bugzilla user name on the |
1006 right. | 1008 right. |
1007 </para> | 1009 </para> |
1008 <programlisting>[usermap] jane.user@example.com = | 1010 <programlisting>[usermap] |
1009 jane</programlisting> | 1011 jane.user@example.com = jane</programlisting> |
1010 <para>You can either keep the <literal | 1012 <para>You can either keep the <literal |
1011 role="rc-usermap">usermap</literal> data in a normal | 1013 role="rc-usermap">usermap</literal> data in a normal |
1012 <filename role="special">~/.hgrc</filename>, or tell the | 1014 <filename role="special">~/.hgrc</filename>, or tell the |
1013 <literal role="hg-ext">bugzilla</literal> hook to read the | 1015 <literal role="hg-ext">bugzilla</literal> hook to read the |
1014 information from an external <filename>usermap</filename> | 1016 information from an external <filename>usermap</filename> |
1015 file. In the latter case, you can store | 1017 file. In the latter case, you can store |
1016 <filename>usermap</filename> data by itself in (for example) | 1018 <filename>usermap</filename> data by itself in (for example) |
1017 a user-modifiable repository. This makes it possible to let | 1019 a user-modifiable repository. This makes it possible to let |
1018 your users maintain their own <envar | 1020 your users maintain their own <envar |
1019 role="rc-item-bugzilla">usermap</envar> entries. The main | 1021 role="rc-item-bugzilla">usermap</envar> entries. The main |
1020 <filename role="special"> /.hgrc</filename>\ file might look | 1022 <filename role="special">~/.hgrc</filename> file might look |
1021 like this: | 1023 like this: |
1022 </para> | 1024 </para> |
1023 <programlisting># regular hgrc file refers to external usermap | 1025 <programlisting># regular hgrc file refers to external usermap file |
1024 file [bugzilla] usermap = | 1026 [bugzilla] |
1025 /home/hg/repos/userdata/bugzilla-usermap.conf</programlisting> | 1027 usermap = /home/hg/repos/userdata/bugzilla-usermap.conf</programlisting> |
1026 <para>While the <filename>usermap</filename> file that it | 1028 <para>While the <filename>usermap</filename> file that it |
1027 refers to might look like this: | 1029 refers to might look like this: |
1028 </para> | 1030 </para> |
1029 <programlisting># bugzilla-usermap.conf - inside a hg | 1031 <programlisting># bugzilla-usermap.conf - inside a hg repository |
1030 repository [usermap] stephanie@example.com = | 1032 [usermap] stephanie@example.com = steph</programlisting> |
1031 steph</programlisting> | |
1032 | 1033 |
1033 </sect3> | 1034 </sect3> |
1034 <sect3> | 1035 <sect3> |
1035 <title>Configuring the text that gets added to a bug</title> | 1036 <title>Configuring the text that gets added to a bug</title> |
1036 | 1037 |
1037 <para>You can configure the text that this hook adds as a | 1038 <para>You can configure the text that this hook adds as a |
1038 comment; you specify it in the form of a Mercurial template. | 1039 comment; you specify it in the form of a Mercurial template. |
1039 Several <filename role="special"> /.hgrc</filename>\ entries | 1040 Several <filename role="special">~/.hgrc</filename> entries |
1040 (still in the <literal role="rc-bugzilla">bugzilla</literal> | 1041 (still in the <literal role="rc-bugzilla">bugzilla</literal> |
1041 section) control this behaviour. | 1042 section) control this behaviour. |
1042 </para> | 1043 </para> |
1043 <itemizedlist> | 1044 <itemizedlist> |
1044 <listitem><para><literal>strip</literal>: The number of | 1045 <listitem><para><literal>strip</literal>: The number of |
1066 </listitem></itemizedlist> | 1067 </listitem></itemizedlist> |
1067 | 1068 |
1068 <para>In addition, you can add a <envar | 1069 <para>In addition, you can add a <envar |
1069 role="rc-item-web">baseurl</envar> item to the <literal | 1070 role="rc-item-web">baseurl</envar> item to the <literal |
1070 role="rc-web">web</literal> section of your <filename | 1071 role="rc-web">web</literal> section of your <filename |
1071 role="special"> /.hgrc</filename>. The <literal | 1072 role="special">~/.hgrc</filename>. The <literal |
1072 role="hg-ext">bugzilla</literal> hook will make this | 1073 role="hg-ext">bugzilla</literal> hook will make this |
1073 available when expanding a template, as the base string to | 1074 available when expanding a template, as the base string to |
1074 use when constructing a URL that will let users browse from | 1075 use when constructing a URL that will let users browse from |
1075 a Bugzilla comment to view a changeset. Example: | 1076 a Bugzilla comment to view a changeset. Example: |
1076 </para> | 1077 </para> |
1077 <programlisting>[web] baseurl = | 1078 <programlisting>[web] |
1078 http://hg.domain.com/</programlisting> | 1079 baseurl = http://hg.domain.com/</programlisting> |
1079 | 1080 |
1080 <para>Here is an example set of <literal | 1081 <para>Here is an example set of <literal |
1081 role="hg-ext">bugzilla</literal> hook config information. | 1082 role="hg-ext">bugzilla</literal> hook config information. |
1082 </para> | 1083 </para> |
1083 <programlisting>[bugzilla] host = bugzilla.example.com | 1084 |
1084 password = mypassword version = 2.16 # server-side repos | 1085 &ch10-bugzilla-config.lst; |
1085 live in /home/hg/repos, so strip 4 leading # separators | |
1086 strip = 4 hgweb = http://hg.example.com/ usermap = | |
1087 /home/hg/repos/notify/bugzilla.conf template = Changeset | |
1088 {node|short}, made by {author} in the {webroot} repo, refers | |
1089 to this bug.\\nFor complete details, see | |
1090 {hgweb}{webroot}?cmd=changeset;node={node|short}\\nChangeset | |
1091 description:\\n\\t{desc|tabindent}</programlisting> | |
1092 | 1086 |
1093 </sect3> | 1087 </sect3> |
1094 <sect3> | 1088 <sect3> |
1095 <title>Testing and troubleshooting</title> | 1089 <title>Testing and troubleshooting</title> |
1096 | 1090 |
1114 <para>You can cause <filename>processmail</filename> to be run | 1108 <para>You can cause <filename>processmail</filename> to be run |
1115 with the suitable user's identity using the | 1109 with the suitable user's identity using the |
1116 <command>sudo</command> command. Here is an example entry | 1110 <command>sudo</command> command. Here is an example entry |
1117 for a <filename>sudoers</filename> file. | 1111 for a <filename>sudoers</filename> file. |
1118 </para> | 1112 </para> |
1119 <programlisting>hg_user = (httpd_user) NOPASSWD: | 1113 <programlisting>hg_user = (httpd_user) |
1120 /var/www/html/bugzilla/processmail-wrapper | 1114 NOPASSWD: /var/www/html/bugzilla/processmail-wrapper %s</programlisting> |
1121 %s</programlisting> | |
1122 <para>This allows the <literal>hg_user</literal> user to run a | 1115 <para>This allows the <literal>hg_user</literal> user to run a |
1123 <filename>processmail-wrapper</filename> program under the | 1116 <filename>processmail-wrapper</filename> program under the |
1124 identity of <literal>httpd_user</literal>. | 1117 identity of <literal>httpd_user</literal>. |
1125 </para> | 1118 </para> |
1126 | 1119 |
1129 with its current directory set to wherever you installed | 1122 with its current directory set to wherever you installed |
1130 Bugzilla; you can't specify that kind of constraint in a | 1123 Bugzilla; you can't specify that kind of constraint in a |
1131 <filename>sudoers</filename> file. The contents of the | 1124 <filename>sudoers</filename> file. The contents of the |
1132 wrapper script are simple: | 1125 wrapper script are simple: |
1133 </para> | 1126 </para> |
1134 <programlisting>#!/bin/sh cd `dirname $0` && | 1127 <programlisting>#!/bin/sh |
1135 ./processmail "$1" nobody@example.com</programlisting> | 1128 cd `dirname $0` && ./processmail "$1" nobody@example.com</programlisting> |
1136 <para>It doesn't seem to matter what email address you pass to | 1129 <para>It doesn't seem to matter what email address you pass to |
1137 <filename>processmail</filename>. | 1130 <filename>processmail</filename>. |
1138 </para> | 1131 </para> |
1139 | 1132 |
1140 <para>If your <literal role="rc-usermap">usermap</literal> is | 1133 <para>If your <literal role="rc-usermap">usermap</literal> is |
1141 not set up correctly, users will see an error message from | 1134 not set up correctly, users will see an error message from |
1142 the <literal role="hg-ext">bugzilla</literal> hook when they | 1135 the <literal role="hg-ext">bugzilla</literal> hook when they |
1143 push changes to the server. The error message will look | 1136 push changes to the server. The error message will look |
1144 like this: | 1137 like this: |
1145 </para> | 1138 </para> |
1146 <programlisting>cannot find bugzilla user id for | 1139 <programlisting>cannot find bugzilla user id for john.q.public@example.com</programlisting> |
1147 john.q.public@example.com</programlisting> | |
1148 <para>What this means is that the committer's address, | 1140 <para>What this means is that the committer's address, |
1149 <literal>john.q.public@example.com</literal>, is not a valid | 1141 <literal>john.q.public@example.com</literal>, is not a valid |
1150 Bugzilla user name, nor does it have an entry in your | 1142 Bugzilla user name, nor does it have an entry in your |
1151 <literal role="rc-usermap">usermap</literal> that maps it to | 1143 <literal role="rc-usermap">usermap</literal> that maps it to |
1152 a valid Bugzilla user name. | 1144 a valid Bugzilla user name. |
1187 role="hg-ext">notify</literal> hook to send one email | 1179 role="hg-ext">notify</literal> hook to send one email |
1188 message per incoming changeset, or one per incoming group of | 1180 message per incoming changeset, or one per incoming group of |
1189 changesets (all those that arrived in a single pull or | 1181 changesets (all those that arrived in a single pull or |
1190 push). | 1182 push). |
1191 </para> | 1183 </para> |
1192 <programlisting>[hooks] # send one email per group of changes | 1184 <programlisting>[hooks] |
1193 changegroup.notify = python:hgext.notify.hook # send one | 1185 # send one email per group of changes |
1194 email per change incoming.notify = | 1186 changegroup.notify = python:hgext.notify.hook |
1195 python:hgext.notify.hook</programlisting> | 1187 # send one email per change |
1188 incoming.notify = python:hgext.notify.hook</programlisting> | |
1196 | 1189 |
1197 <para>Configuration information for this hook lives in the | 1190 <para>Configuration information for this hook lives in the |
1198 <literal role="rc-notify">notify</literal> section of a | 1191 <literal role="rc-notify">notify</literal> section of a |
1199 <filename role="special"> /.hgrc</filename>\ file. | 1192 <filename role="special">~/.hgrc</filename> file. |
1200 </para> | 1193 </para> |
1201 <itemizedlist> | 1194 <itemizedlist> |
1202 <listitem><para><envar role="rc-item-notify">test</envar>: | 1195 <listitem><para><envar role="rc-item-notify">test</envar>: |
1203 By default, this hook does not send out email at all; | 1196 By default, this hook does not send out email at all; |
1204 instead, it prints the message that it | 1197 instead, it prints the message that it |
1212 </para> | 1205 </para> |
1213 </listitem> | 1206 </listitem> |
1214 <listitem><para><envar role="rc-item-notify">config</envar>: | 1207 <listitem><para><envar role="rc-item-notify">config</envar>: |
1215 The path to a configuration file that contains | 1208 The path to a configuration file that contains |
1216 subscription information. This is kept separate from | 1209 subscription information. This is kept separate from |
1217 the main <filename role="special"> /.hgrc</filename>\ so | 1210 the main <filename role="special">~/.hgrc</filename> so |
1218 that you can maintain it in a repository of its own. | 1211 that you can maintain it in a repository of its own. |
1219 People can then clone that repository, update their | 1212 People can then clone that repository, update their |
1220 subscriptions, and push the changes back to your server. | 1213 subscriptions, and push the changes back to your server. |
1221 </para> | 1214 </para> |
1222 </listitem> | 1215 </listitem> |
1271 </para> | 1264 </para> |
1272 | 1265 |
1273 <para>Here is an example set of <literal | 1266 <para>Here is an example set of <literal |
1274 role="hg-ext">notify</literal> configuration information. | 1267 role="hg-ext">notify</literal> configuration information. |
1275 </para> | 1268 </para> |
1276 <programlisting> | 1269 |
1277 [notify] # really send email test = false # subscriber data | 1270 &ch10-notify-config.lst; |
1278 lives in the notify repo config = | |
1279 /home/hg/repos/notify/notify.conf # repos live in | |
1280 /home/hg/repos on server, so strip 4 "/" chars strip = 4 | |
1281 template = X-Hg-Repo: {webroot} Subject: {webroot}: | |
1282 {desc|firstline|strip} From: {author} changeset {node|short} | |
1283 in {root} details: | |
1284 {baseurl}{webroot}?cmd=changeset;node={node|short} | |
1285 description: {desc|tabindent|strip} [web] baseurl = | |
1286 http://hg.example.com/ | |
1287 </programlisting> | |
1288 | 1271 |
1289 <para>This will produce a message that looks like the | 1272 <para>This will produce a message that looks like the |
1290 following: | 1273 following: |
1291 </para> | 1274 </para> |
1292 <programlisting> | 1275 |
1293 X-Hg-Repo: tests/slave Subject: tests/slave: Handle error | 1276 &ch10-notify-config-mail.lst; |
1294 case when slave has no buffers Date: Wed, 2 Aug 2006 | |
1295 15:25:46 -0700 (PDT) changeset 3cba9bfe74b5 in | |
1296 /home/hg/repos/tests/slave details: | |
1297 http://hg.example.com/tests/slave?cmd=changeset;node=3cba9bfe74b5 | |
1298 description: Handle error case when slave has no buffers | |
1299 diffs (54 lines): diff -r 9d95df7cf2ad -r 3cba9bfe74b5 | |
1300 include/tests.h --- a/include/tests.h Wed Aug 02 | |
1301 15:19:52 2006 -0700 +++ b/include/tests.h Wed Aug 02 | |
1302 15:25:26 2006 -0700 @@ -212,6 +212,15 @@ static __inline__ | |
1303 void test_headers(void *h) [...snip...] | |
1304 </programlisting> | |
1305 | 1277 |
1306 </sect3> | 1278 </sect3> |
1307 <sect3> | 1279 <sect3> |
1308 <title>Testing and troubleshooting</title> | 1280 <title>Testing and troubleshooting</title> |
1309 | 1281 |
1325 <title>In-process hook execution</title> | 1297 <title>In-process hook execution</title> |
1326 | 1298 |
1327 <para>An in-process hook is called with arguments of the | 1299 <para>An in-process hook is called with arguments of the |
1328 following form: | 1300 following form: |
1329 </para> | 1301 </para> |
1330 <programlisting> | 1302 <programlisting>def myhook(ui, repo, **kwargs): pass</programlisting> |
1331 def myhook(ui, repo, **kwargs): pass | |
1332 </programlisting> | |
1333 <para>The <literal>ui</literal> parameter is a <literal | 1303 <para>The <literal>ui</literal> parameter is a <literal |
1334 role="py-mod-mercurial.ui">ui</literal> object. The | 1304 role="py-mod-mercurial.ui">ui</literal> object. The |
1335 <literal>repo</literal> parameter is a <literal | 1305 <literal>repo</literal> parameter is a <literal |
1336 role="py-mod-mercurial.localrepo">localrepository</literal> | 1306 role="py-mod-mercurial.localrepo">localrepository</literal> |
1337 object. The names and values of the | 1307 object. The names and values of the |
1371 </para> | 1341 </para> |
1372 | 1342 |
1373 <para>Note that changeset IDs are passed into Python hooks as | 1343 <para>Note that changeset IDs are passed into Python hooks as |
1374 hexadecimal strings, not the binary hashes that Mercurial's | 1344 hexadecimal strings, not the binary hashes that Mercurial's |
1375 APIs normally use. To convert a hash from hex to binary, use | 1345 APIs normally use. To convert a hash from hex to binary, use |
1376 the \pymodfunc{mercurial.node}{bin} function. | 1346 the <literal>bin</literal> function. |
1377 </para> | 1347 </para> |
1378 | 1348 |
1379 </sect2> | 1349 </sect2> |
1380 <sect2> | 1350 <sect2> |
1381 <title>External hook execution</title> | 1351 <title>External hook execution</title> |
1524 </para> | 1494 </para> |
1525 <itemizedlist> | 1495 <itemizedlist> |
1526 <listitem><para><literal>node</literal>: A changeset ID. The | 1496 <listitem><para><literal>node</literal>: A changeset ID. The |
1527 changeset ID of the first changeset in the group that was | 1497 changeset ID of the first changeset in the group that was |
1528 added. All changesets between this and | 1498 added. All changesets between this and |
1529 \index{tags!<literal>tip</literal>}<literal>tip</literal>, | 1499 <literal role="tag">tip</literal>, inclusive, were added by a single |
1530 inclusive, were added by a single <command | 1500 <command role="hg-cmd">hg pull</command>, <command |
1531 role="hg-cmd">hg pull</command>, <command | |
1532 role="hg-cmd">hg push</command> or <command | 1501 role="hg-cmd">hg push</command> or <command |
1533 role="hg-cmd">hg unbundle</command>. | 1502 role="hg-cmd">hg unbundle</command>. |
1534 </para> | 1503 </para> |
1535 </listitem> | 1504 </listitem> |
1536 <listitem><para><literal>source</literal>: A string. The | 1505 <listitem><para><literal>source</literal>: A string. The |
1878 </para> | 1847 </para> |
1879 <itemizedlist> | 1848 <itemizedlist> |
1880 <listitem><para><literal>node</literal>: A changeset ID. The | 1849 <listitem><para><literal>node</literal>: A changeset ID. The |
1881 changeset ID of the first changeset in the group that was | 1850 changeset ID of the first changeset in the group that was |
1882 added. All changesets between this and | 1851 added. All changesets between this and |
1883 \index{tags!<literal>tip</literal>}<literal>tip</literal>, | 1852 <literal role="tag">tip</literal>, |
1884 inclusive, were added by a single <command | 1853 inclusive, were added by a single <command |
1885 role="hg-cmd">hg pull</command>, <command | 1854 role="hg-cmd">hg pull</command>, <command |
1886 role="hg-cmd">hg push</command> or <command | 1855 role="hg-cmd">hg push</command> or <command |
1887 role="hg-cmd">hg unbundle</command>. | 1856 role="hg-cmd">hg unbundle</command>. |
1888 </para> | 1857 </para> |