hgext/notify.py
author Denis Laxalde <denis.laxalde@logilab.fr>
Thu, 24 Oct 2019 15:28:00 +0200
branchstable
changeset 43326 ef81de93143e
parent 43322 7d912413a3ae
child 43327 ac33550f63e8
permissions -rw-r--r--
py3: use a BytesParser in notify extension This is the first step to make the "long line" case in test-notify.t pass by fixing a UnicodeDecodeError on Python 3. We alias a parsebytes() in mail module, similarly as we already have a parse() function for Python 2 and Python 3 compatibility.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
     1
# notify.py - email notifications for mercurial
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
     2
#
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
     3
# Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
     4
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8154
diff changeset
     5
# This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 10112
diff changeset
     6
# GNU General Public License version 2 or any later version.
7127
9df67ee30ef5 help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7116
diff changeset
     7
14940
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
     8
'''hooks for sending email push notifications
7127
9df67ee30ef5 help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7116
diff changeset
     9
16950
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    10
This extension implements hooks to send email notifications when
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    11
changesets are sent from or received by the local repository.
7127
9df67ee30ef5 help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7116
diff changeset
    12
14940
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    13
First, enable the extension as explained in :hg:`help extensions`, and
16500
8436a4e21417 doc: fix careless document miss in help of hgext/notify
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 15654
diff changeset
    14
register the hook you want to run. ``incoming`` and ``changegroup`` hooks
16950
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    15
are run when changesets are received, while ``outgoing`` hooks are for
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    16
changesets sent to another repository::
7127
9df67ee30ef5 help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7116
diff changeset
    17
9105
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
    18
  [hooks]
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
    19
  # one email for each incoming changeset
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
    20
  incoming.notify = python:hgext.notify.hook
14940
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    21
  # one email for all incoming changesets
9105
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
    22
  changegroup.notify = python:hgext.notify.hook
14940
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    23
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    24
  # one email for all outgoing changesets
14617
23f4e1e40988 notify: send changesets on 'outgoing' hook, updated doc
Ingo Bressler <dev@ingobressler.net>
parents: 13878
diff changeset
    25
  outgoing.notify = python:hgext.notify.hook
7127
9df67ee30ef5 help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7116
diff changeset
    26
16950
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    27
This registers the hooks. To enable notification, subscribers must
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    28
be assigned to repositories. The ``[usersubs]`` section maps multiple
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    29
repositories to a given recipient. The ``[reposubs]`` section maps
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    30
multiple recipients to a single repository::
9157
9261667e9b82 commands: use minirst parser when displaying help
Martin Geisler <mg@lazybytes.net>
parents: 9136
diff changeset
    31
9105
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
    32
  [usersubs]
17754
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
    33
  # key is subscriber email, value is a comma-separated list of repo patterns
9105
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
    34
  user@host = pattern
7127
9df67ee30ef5 help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7116
diff changeset
    35
9105
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
    36
  [reposubs]
17754
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
    37
  # key is repo pattern, value is a comma-separated list of subscriber emails
9105
6188f2cc4a37 notify: fix indentation in module docstring
Martin Geisler <mg@lazybytes.net>
parents: 9104
diff changeset
    38
  pattern = user@host
7127
9df67ee30ef5 help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7116
diff changeset
    39
17754
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
    40
A ``pattern`` is a ``glob`` matching the absolute path to a repository,
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
    41
optionally combined with a revset expression. A revset expression, if
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
    42
present, is separated from the glob by a hash. Example::
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
    43
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
    44
  [reposubs]
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
    45
  */widgets#branch(release) = qa-team@example.com
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
    46
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
    47
This sends to ``qa-team@example.com`` whenever a changeset on the ``release``
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
    48
branch triggers a notification in any repository ending in ``widgets``.
16950
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    49
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    50
In order to place them under direct user management, ``[usersubs]`` and
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    51
``[reposubs]`` sections may be placed in a separate ``hgrc`` file and
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    52
incorporated by reference::
14940
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    53
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    54
  [notify]
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    55
  config = /path/to/subscriptionsfile
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    56
16950
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    57
Notifications will not be sent until the ``notify.test`` value is set
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    58
to ``False``; see below.
14940
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    59
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    60
Notifications content can be tweaked with the following configuration entries:
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    61
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    62
notify.test
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    63
  If ``True``, print messages to stdout instead of sending them. Default: True.
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    64
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    65
notify.sources
16950
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    66
  Space-separated list of change sources. Notifications are activated only
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    67
  when a changeset's source is in this list. Sources may be:
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    68
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    69
  :``serve``: changesets received via http or ssh
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    70
  :``pull``: changesets received via ``hg pull``
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    71
  :``unbundle``: changesets received via ``hg unbundle``
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    72
  :``push``: changesets sent or received via ``hg push``
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    73
  :``bundle``: changesets sent via ``hg unbundle``
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    74
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    75
  Default: serve.
14940
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    76
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    77
notify.strip
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    78
  Number of leading slashes to strip from url paths. By default, notifications
16950
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    79
  reference repositories with their absolute path. ``notify.strip`` lets you
14940
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    80
  turn them into relative paths. For example, ``notify.strip=3`` will change
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    81
  ``/long/path/repository`` into ``repository``. Default: 0.
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    82
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    83
notify.domain
16950
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    84
  Default email domain for sender or recipients with no explicit domain.
42910
d26a6706b070 notify: add option for deterministic message-id generation
Joerg Sonnenberger <joerg@bec.de>
parents: 41426
diff changeset
    85
  It is also used for the domain part of the ``Message-Id`` when using
d26a6706b070 notify: add option for deterministic message-id generation
Joerg Sonnenberger <joerg@bec.de>
parents: 41426
diff changeset
    86
  ``notify.messageidseed``.
d26a6706b070 notify: add option for deterministic message-id generation
Joerg Sonnenberger <joerg@bec.de>
parents: 41426
diff changeset
    87
d26a6706b070 notify: add option for deterministic message-id generation
Joerg Sonnenberger <joerg@bec.de>
parents: 41426
diff changeset
    88
notify.messageidseed
d26a6706b070 notify: add option for deterministic message-id generation
Joerg Sonnenberger <joerg@bec.de>
parents: 41426
diff changeset
    89
  Create deterministic ``Message-Id`` headers for the mails based on the seed
d26a6706b070 notify: add option for deterministic message-id generation
Joerg Sonnenberger <joerg@bec.de>
parents: 41426
diff changeset
    90
  and the revision identifier of the first commit in the changeset.
7127
9df67ee30ef5 help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7116
diff changeset
    91
14940
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    92
notify.style
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    93
  Style file to use when formatting emails.
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    94
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    95
notify.template
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    96
  Template to use when formatting emails.
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    97
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
    98
notify.incoming
16950
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
    99
  Template to use when run as an incoming hook, overriding ``notify.template``.
14940
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
   100
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
   101
notify.outgoing
16950
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
   102
  Template to use when run as an outgoing hook, overriding ``notify.template``.
14940
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
   103
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
   104
notify.changegroup
16950
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
   105
  Template to use when running as a changegroup hook, overriding
14940
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
   106
  ``notify.template``.
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
   107
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
   108
notify.maxdiff
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
   109
  Maximum number of diff lines to include in notification email. Set to 0
16950
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
   110
  to disable the diff, or -1 to include all of it. Default: 300.
14940
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
   111
37777
a4cac7b0ea4f notify: add maxdiffstat option to truncate long file lists
Joerg Sonnenberger <joerg@bec.de>
parents: 37087
diff changeset
   112
notify.maxdiffstat
a4cac7b0ea4f notify: add maxdiffstat option to truncate long file lists
Joerg Sonnenberger <joerg@bec.de>
parents: 37087
diff changeset
   113
  Maximum number of diffstat lines to include in notification email. Set to -1
a4cac7b0ea4f notify: add maxdiffstat option to truncate long file lists
Joerg Sonnenberger <joerg@bec.de>
parents: 37087
diff changeset
   114
  to include all of it. Default: -1.
a4cac7b0ea4f notify: add maxdiffstat option to truncate long file lists
Joerg Sonnenberger <joerg@bec.de>
parents: 37087
diff changeset
   115
14940
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
   116
notify.maxsubject
16950
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
   117
  Maximum number of characters in email's subject line. Default: 67.
14940
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
   118
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
   119
notify.diffstat
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
   120
  Set to True to include a diffstat before diff content. Default: True.
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
   121
38070
d1134ca5b1a3 notify: add option to include function names in the diff output
Joerg Sonnenberger <joerg@bec.de>
parents: 37795
diff changeset
   122
notify.showfunc
d1134ca5b1a3 notify: add option to include function names in the diff output
Joerg Sonnenberger <joerg@bec.de>
parents: 37795
diff changeset
   123
  If set, override ``diff.showfunc`` for the diff content. Default: None.
d1134ca5b1a3 notify: add option to include function names in the diff output
Joerg Sonnenberger <joerg@bec.de>
parents: 37795
diff changeset
   124
14940
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
   125
notify.merge
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
   126
  If True, send notifications for merge changesets. Default: True.
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
   127
15561
ca572e94d8e7 notify: add option for writing to mbox
Mads Kiilerich <mads@kiilerich.com>
parents: 14940
diff changeset
   128
notify.mbox
ca572e94d8e7 notify: add option for writing to mbox
Mads Kiilerich <mads@kiilerich.com>
parents: 14940
diff changeset
   129
  If set, append mails to this mbox file instead of sending. Default: None.
ca572e94d8e7 notify: add option for writing to mbox
Mads Kiilerich <mads@kiilerich.com>
parents: 14940
diff changeset
   130
15654
2a7fa7c641d8 notify: change behavior of "changegroup" hook
Nikolaus Schueler <nikolaus.schueler@lantiq.com>
parents: 15561
diff changeset
   131
notify.fromauthor
16950
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
   132
  If set, use the committer of the first changeset in a changegroup for
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
   133
  the "From" field of the notification mail. If not set, take the user
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
   134
  from the pushing repo.  Default: False.
15654
2a7fa7c641d8 notify: change behavior of "changegroup" hook
Nikolaus Schueler <nikolaus.schueler@lantiq.com>
parents: 15561
diff changeset
   135
16950
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
   136
If set, the following entries will also be used to customize the
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
   137
notifications:
14940
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
   138
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
   139
email.from
16950
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
   140
  Email ``From`` address to use if none can be found in the generated
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
   141
  email content.
14940
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
   142
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
   143
web.baseurl
16950
0fdd8193c8b5 notify: various fixes to docstring
David Champion <dgc@uchicago.edu>
parents: 16500
diff changeset
   144
  Root repository URL to combine with repository paths when making
14940
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
   145
  references. See also ``notify.strip``.
d78b92353f26 notify: rewrite user documentation
Patrick Mezard <pmezard@gmail.com>
parents: 14869
diff changeset
   146
9068
27a41250a9ce notify: wrapped docstrings at 78 characters
Martin Geisler <mg@lazybytes.net>
parents: 8935
diff changeset
   147
'''
28416
d3c8183f429e notify: use absolute_import
timeless <timeless@mozdev.org>
parents: 26587
diff changeset
   148
from __future__ import absolute_import
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   149
40290
091f9b8a1051 notify: just use email.errors
Yuya Nishihara <yuya@tcha.org>
parents: 40284
diff changeset
   150
import email.errors as emailerrors
28416
d3c8183f429e notify: use absolute_import
timeless <timeless@mozdev.org>
parents: 26587
diff changeset
   151
import fnmatch
42910
d26a6706b070 notify: add option for deterministic message-id generation
Joerg Sonnenberger <joerg@bec.de>
parents: 41426
diff changeset
   152
import hashlib
28416
d3c8183f429e notify: use absolute_import
timeless <timeless@mozdev.org>
parents: 26587
diff changeset
   153
import socket
d3c8183f429e notify: use absolute_import
timeless <timeless@mozdev.org>
parents: 26587
diff changeset
   154
import time
d3c8183f429e notify: use absolute_import
timeless <timeless@mozdev.org>
parents: 26587
diff changeset
   155
29205
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 28951
diff changeset
   156
from mercurial.i18n import _
28416
d3c8183f429e notify: use absolute_import
timeless <timeless@mozdev.org>
parents: 26587
diff changeset
   157
from mercurial import (
40304
f6ef89cf8234 notify: a ton of encoding dancing to deal with the email module
Augie Fackler <augie@google.com>
parents: 40290
diff changeset
   158
    encoding,
28416
d3c8183f429e notify: use absolute_import
timeless <timeless@mozdev.org>
parents: 26587
diff changeset
   159
    error,
35928
c8e2d6ed1f9e cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35633
diff changeset
   160
    logcmdutil,
28416
d3c8183f429e notify: use absolute_import
timeless <timeless@mozdev.org>
parents: 26587
diff changeset
   161
    mail,
d3c8183f429e notify: use absolute_import
timeless <timeless@mozdev.org>
parents: 26587
diff changeset
   162
    patch,
43164
c32531444cdc notify: cast hash to bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43117
diff changeset
   163
    pycompat,
33764
2069a8c336b9 configitems: register the 'notify.config' config
Boris Feld <boris.feld@octobus.net>
parents: 32857
diff changeset
   164
    registrar,
28416
d3c8183f429e notify: use absolute_import
timeless <timeless@mozdev.org>
parents: 26587
diff changeset
   165
    util,
d3c8183f429e notify: use absolute_import
timeless <timeless@mozdev.org>
parents: 26587
diff changeset
   166
)
37087
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36636
diff changeset
   167
from mercurial.utils import (
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36636
diff changeset
   168
    dateutil,
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36636
diff changeset
   169
    stringutil,
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36636
diff changeset
   170
)
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   171
29852
d5883fd055c6 extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents: 29240
diff changeset
   172
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
25186
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 24987
diff changeset
   173
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 24987
diff changeset
   174
# be specifying the version(s) of Mercurial they are tested with, or
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 24987
diff changeset
   175
# leave the attribute unspecified.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   176
testedwith = b'ships-with-hg-core'
16743
38caf405d010 hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents: 16683
diff changeset
   177
33764
2069a8c336b9 configitems: register the 'notify.config' config
Boris Feld <boris.feld@octobus.net>
parents: 32857
diff changeset
   178
configtable = {}
2069a8c336b9 configitems: register the 'notify.config' config
Boris Feld <boris.feld@octobus.net>
parents: 32857
diff changeset
   179
configitem = registrar.configitem(configtable)
2069a8c336b9 configitems: register the 'notify.config' config
Boris Feld <boris.feld@octobus.net>
parents: 32857
diff changeset
   180
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   181
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   182
    b'notify', b'changegroup', default=None,
34754
a0a727104eed configitem: register the 'notify.changegroup' config
Boris Feld <boris.feld@octobus.net>
parents: 34753
diff changeset
   183
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   184
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   185
    b'notify', b'config', default=None,
33764
2069a8c336b9 configitems: register the 'notify.config' config
Boris Feld <boris.feld@octobus.net>
parents: 32857
diff changeset
   186
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   187
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   188
    b'notify', b'diffstat', default=True,
33765
b30da11d9233 configitems: register the 'notify.diffstat' config
Boris Feld <boris.feld@octobus.net>
parents: 33764
diff changeset
   189
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   190
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   191
    b'notify', b'domain', default=None,
33766
a853325102a0 configitems: register the 'notify.domain' config
Boris Feld <boris.feld@octobus.net>
parents: 33765
diff changeset
   192
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   193
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   194
    b'notify', b'messageidseed', default=None,
42910
d26a6706b070 notify: add option for deterministic message-id generation
Joerg Sonnenberger <joerg@bec.de>
parents: 41426
diff changeset
   195
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   196
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   197
    b'notify', b'fromauthor', default=None,
33767
b14be4deac06 configitems: register the 'notify.fromauthor' config
Boris Feld <boris.feld@octobus.net>
parents: 33766
diff changeset
   198
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   199
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   200
    b'notify', b'incoming', default=None,
34752
b811f06b144d configitem: register the 'notify.incoming' config
Boris Feld <boris.feld@octobus.net>
parents: 33776
diff changeset
   201
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   202
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   203
    b'notify', b'maxdiff', default=300,
33768
66860180b009 configitems: register the 'notify.maxdiff' config
Boris Feld <boris.feld@octobus.net>
parents: 33767
diff changeset
   204
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   205
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   206
    b'notify', b'maxdiffstat', default=-1,
37777
a4cac7b0ea4f notify: add maxdiffstat option to truncate long file lists
Joerg Sonnenberger <joerg@bec.de>
parents: 37087
diff changeset
   207
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   208
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   209
    b'notify', b'maxsubject', default=67,
33769
3d08f4810690 configitems: register the 'notify.maxsubject' config
Boris Feld <boris.feld@octobus.net>
parents: 33768
diff changeset
   210
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   211
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   212
    b'notify', b'mbox', default=None,
33770
b76dc3e6bf99 configitems: register the 'notify.mbox' config
Boris Feld <boris.feld@octobus.net>
parents: 33769
diff changeset
   213
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   214
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   215
    b'notify', b'merge', default=True,
33771
8bf8ed0deab8 configitems: register the 'notify.merge' config
Boris Feld <boris.feld@octobus.net>
parents: 33770
diff changeset
   216
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   217
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   218
    b'notify', b'outgoing', default=None,
34753
12a69c806382 configitem: register the 'notify.outgoing' config
Boris Feld <boris.feld@octobus.net>
parents: 34752
diff changeset
   219
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   220
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   221
    b'notify', b'sources', default=b'serve',
33772
20189ba5fddf configitems: register the 'notify.sources' config
Boris Feld <boris.feld@octobus.net>
parents: 33771
diff changeset
   222
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   223
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   224
    b'notify', b'showfunc', default=None,
38070
d1134ca5b1a3 notify: add option to include function names in the diff output
Joerg Sonnenberger <joerg@bec.de>
parents: 37795
diff changeset
   225
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   226
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   227
    b'notify', b'strip', default=0,
33773
71665bbe82c1 configitems: register the 'notify.strip' config
Boris Feld <boris.feld@octobus.net>
parents: 33772
diff changeset
   228
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   229
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   230
    b'notify', b'style', default=None,
33774
c27fac1ca8ed configitems: register the 'notify.style' config
Boris Feld <boris.feld@octobus.net>
parents: 33773
diff changeset
   231
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   232
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   233
    b'notify', b'template', default=None,
33775
ff4a11ff7aa3 configitems: register the 'notify.template' config
Boris Feld <boris.feld@octobus.net>
parents: 33774
diff changeset
   234
)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   235
configitem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   236
    b'notify', b'test', default=True,
33776
a0e28577f7d4 configitems: register the 'notify.test' config
Boris Feld <boris.feld@octobus.net>
parents: 33775
diff changeset
   237
)
33764
2069a8c336b9 configitems: register the 'notify.config' config
Boris Feld <boris.feld@octobus.net>
parents: 32857
diff changeset
   238
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   239
# template for single changeset can include email headers.
40283
c7a363ca04b9 notify: add some b prefixes
Augie Fackler <augie@google.com>
parents: 38070
diff changeset
   240
single_template = b'''
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   241
Subject: changeset in {webroot}: {desc|firstline|strip}
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   242
From: {author}
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   243
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   244
changeset {node|short} in {root}
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   245
details: {baseurl}{webroot}?cmd=changeset;node={node|short}
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   246
description:
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   247
\t{desc|tabindent|strip}
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   248
'''.lstrip()
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   249
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   250
# template for multiple changesets should not contain email headers,
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   251
# because only first set of headers will be used and result will look
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   252
# strange.
40283
c7a363ca04b9 notify: add some b prefixes
Augie Fackler <augie@google.com>
parents: 38070
diff changeset
   253
multiple_template = b'''
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   254
changeset {node|short} in {root}
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   255
details: {baseurl}{webroot}?cmd=changeset;node={node|short}
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   256
summary: {desc|firstline}
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   257
'''
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   258
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   259
deftemplates = {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   260
    b'changegroup': multiple_template,
4498
4dfb9f232a63 Fixed indentation in hgext/notify.py
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4479
diff changeset
   261
}
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   262
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   263
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   264
class notifier(object):
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   265
    '''email notification class.'''
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   266
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   267
    def __init__(self, ui, repo, hooktype):
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   268
        self.ui = ui
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   269
        cfg = self.ui.config(b'notify', b'config')
2329
90368f89340a notify: add debug output. do not fail if no config file.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2326
diff changeset
   270
        if cfg:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   271
            self.ui.readconfig(cfg, sections=[b'usersubs', b'reposubs'])
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   272
        self.repo = repo
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   273
        self.stripcount = int(self.ui.config(b'notify', b'strip'))
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   274
        self.root = self.strip(self.repo.root)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   275
        self.domain = self.ui.config(b'notify', b'domain')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   276
        self.mbox = self.ui.config(b'notify', b'mbox')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   277
        self.test = self.ui.configbool(b'notify', b'test')
7116
e981725da3fe notify: mime-encode messages
Christian Ebert <blacktrash@gmx.net>
parents: 6979
diff changeset
   278
        self.charsets = mail._charsets(self.ui)
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   279
        self.subs = self.subscribers()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   280
        self.merge = self.ui.configbool(b'notify', b'merge')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   281
        self.showfunc = self.ui.configbool(b'notify', b'showfunc')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   282
        self.messageidseed = self.ui.config(b'notify', b'messageidseed')
38070
d1134ca5b1a3 notify: add option to include function names in the diff output
Joerg Sonnenberger <joerg@bec.de>
parents: 37795
diff changeset
   283
        if self.showfunc is None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   284
            self.showfunc = self.ui.configbool(b'diff', b'showfunc')
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   285
28951
1bba1b43525a notify: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 28416
diff changeset
   286
        mapfile = None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   287
        template = self.ui.config(b'notify', hooktype) or self.ui.config(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   288
            b'notify', b'template'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   289
        )
28951
1bba1b43525a notify: do not load style file if template is specified (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 28416
diff changeset
   290
        if not template:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   291
            mapfile = self.ui.config(b'notify', b'style')
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   292
        if not mapfile and not template:
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   293
            template = deftemplates.get(hooktype) or single_template
35928
c8e2d6ed1f9e cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35633
diff changeset
   294
        spec = logcmdutil.templatespec(template, mapfile)
35993
386c1e45e671 logcmdutil: drop default arguments from changesetdisplayer/templater() calls
Yuya Nishihara <yuya@tcha.org>
parents: 35928
diff changeset
   295
        self.t = logcmdutil.changesettemplater(self.ui, self.repo, spec)
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   296
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   297
    def strip(self, path):
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   298
        '''strip leading slashes from local path, turn into web-safe path.'''
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   299
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   300
        path = util.pconvert(path)
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   301
        count = self.stripcount
2326
d0ba2f6b9d97 notify: fix off by one error.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2296
diff changeset
   302
        while count > 0:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   303
            c = path.find(b'/')
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   304
            if c == -1:
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   305
                break
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   306
            path = path[c + 1 :]
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   307
            count -= 1
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   308
        return path
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   309
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   310
    def fixmail(self, addr):
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   311
        '''try to clean up email addresses.'''
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   312
37087
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36636
diff changeset
   313
        addr = stringutil.email(addr.strip())
4094
fbf0e9acfd83 notify: don't try to fix addresses if notify.domain is not set
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4077
diff changeset
   314
        if self.domain:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   315
            a = addr.find(b'@localhost')
4094
fbf0e9acfd83 notify: don't try to fix addresses if notify.domain is not set
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4077
diff changeset
   316
            if a != -1:
fbf0e9acfd83 notify: don't try to fix addresses if notify.domain is not set
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4077
diff changeset
   317
                addr = addr[:a]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   318
            if b'@' not in addr:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   319
                return addr + b'@' + self.domain
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   320
        return addr
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   321
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   322
    def subscribers(self):
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   323
        '''return list of email addresses of subscribers to this repo.'''
8154
06f1e4e309ed notify: turned a set-like dict into a real set
Martin Geisler <mg@lazybytes.net>
parents: 8142
diff changeset
   324
        subs = set()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   325
        for user, pats in self.ui.configitems(b'usersubs'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   326
            for pat in pats.split(b','):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   327
                if b'#' in pat:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   328
                    pat, revs = pat.split(b'#', 1)
17754
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
   329
                else:
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
   330
                    revs = None
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   331
                if fnmatch.fnmatch(self.repo.root, pat.strip()):
17754
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
   332
                    subs.add((self.fixmail(user), revs))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   333
        for pat, users in self.ui.configitems(b'reposubs'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   334
            if b'#' in pat:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   335
                pat, revs = pat.split(b'#', 1)
17754
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
   336
            else:
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
   337
                revs = None
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   338
            if fnmatch.fnmatch(self.repo.root, pat):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   339
                for user in users.split(b','):
17754
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
   340
                    subs.add((self.fixmail(user), revs))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   341
        return [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   342
            (mail.addressencode(self.ui, s, self.charsets, self.test), r)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   343
            for s, r in sorted(subs)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   344
        ]
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   345
9486
dd8d10c36c9c notify: make it possible to pass extra info into templates
Bryan O'Sullivan <bos@serpentine.com>
parents: 9327
diff changeset
   346
    def node(self, ctx, **props):
9516
f8048c334066 notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents: 9487
diff changeset
   347
        '''format one changeset, unless it is a suppressed merge.'''
f8048c334066 notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents: 9487
diff changeset
   348
        if not self.merge and len(ctx.parents()) > 1:
f8048c334066 notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents: 9487
diff changeset
   349
            return False
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   350
        self.t.show(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   351
            ctx,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   352
            changes=ctx.changeset(),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   353
            baseurl=self.ui.config(b'web', b'baseurl'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   354
            root=self.repo.root,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   355
            webroot=self.root,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   356
            **props
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   357
        )
9516
f8048c334066 notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents: 9487
diff changeset
   358
        return True
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   359
2230
332950340788 localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2225
diff changeset
   360
    def skipsource(self, source):
332950340788 localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2225
diff changeset
   361
        '''true if incoming changes from this source should be skipped.'''
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   362
        ok_sources = self.ui.config(b'notify', b'sources').split()
2230
332950340788 localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2225
diff changeset
   363
        return source not in ok_sources
332950340788 localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2225
diff changeset
   364
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
   365
    def send(self, ctx, count, data):
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   366
        '''send message.'''
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   367
17754
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
   368
        # Select subscribers by revset
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
   369
        subs = set()
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
   370
        for sub, spec in self.subs:
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
   371
            if spec is None:
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
   372
                subs.add(sub)
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
   373
                continue
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   374
            revs = self.repo.revs(b'%r and %d:', spec, ctx.rev())
17754
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
   375
            if len(revs):
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
   376
                subs.add(sub)
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
   377
                continue
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
   378
        if len(subs) == 0:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   379
            self.ui.debug(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43077
diff changeset
   380
                b'notify: no subscribers to selected repo and revset\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   381
            )
17754
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
   382
            return
19e9bf7c0927 notify: support revset selection for subscriptions
Michal Sznajder <michalsznajder@gmail.com>
parents: 16951
diff changeset
   383
9313
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
   384
        try:
43326
ef81de93143e py3: use a BytesParser in notify extension
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43322
diff changeset
   385
            msg = mail.parsebytes(data)
40284
46b55f279571 notify: adapt to new location of email module's errors
Augie Fackler <augie@google.com>
parents: 40283
diff changeset
   386
        except emailerrors.MessageParseError as inst:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26503
diff changeset
   387
            raise error.Abort(inst)
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   388
7116
e981725da3fe notify: mime-encode messages
Christian Ebert <blacktrash@gmx.net>
parents: 6979
diff changeset
   389
        # store sender and subject
41426
43f9b8c0574b notify: be more defensive aboute None values
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40304
diff changeset
   390
        sender = msg[r'From']
43f9b8c0574b notify: be more defensive aboute None values
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40304
diff changeset
   391
        subject = msg[r'Subject']
43f9b8c0574b notify: be more defensive aboute None values
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40304
diff changeset
   392
        if sender is not None:
43f9b8c0574b notify: be more defensive aboute None values
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40304
diff changeset
   393
            sender = encoding.strtolocal(sender)
43f9b8c0574b notify: be more defensive aboute None values
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40304
diff changeset
   394
        if subject is not None:
43f9b8c0574b notify: be more defensive aboute None values
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40304
diff changeset
   395
            subject = encoding.strtolocal(subject)
40304
f6ef89cf8234 notify: a ton of encoding dancing to deal with the email module
Augie Fackler <augie@google.com>
parents: 40290
diff changeset
   396
        del msg[r'From'], msg[r'Subject']
9313
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
   397
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
   398
        if not msg.is_multipart():
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
   399
            # create fresh mime message from scratch
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
   400
            # (multipart templates must take care of this themselves)
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
   401
            headers = msg.items()
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
   402
            payload = msg.get_payload()
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
   403
            # for notification prefer readability over data precision
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
   404
            msg = mail.mimeencode(self.ui, payload, self.charsets, self.test)
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
   405
            # reinstate custom headers
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
   406
            for k, v in headers:
8736b1c853ff notify: do not mime encode multipart templates
Christian Ebert <blacktrash@gmx.net>
parents: 8935
diff changeset
   407
                msg[k] = v
7116
e981725da3fe notify: mime-encode messages
Christian Ebert <blacktrash@gmx.net>
parents: 6979
diff changeset
   408
40304
f6ef89cf8234 notify: a ton of encoding dancing to deal with the email module
Augie Fackler <augie@google.com>
parents: 40290
diff changeset
   409
        msg[r'Date'] = encoding.strfromlocal(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   410
            dateutil.datestr(format=b"%a, %d %b %Y %H:%M:%S %1%2")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   411
        )
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   412
7705
c55e68e8f256 notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents: 7658
diff changeset
   413
        # try to make subject line exist and be useful
c55e68e8f256 notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents: 7658
diff changeset
   414
        if not subject:
c55e68e8f256 notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents: 7658
diff changeset
   415
            if count > 1:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   416
                subject = _(b'%s: %d new changesets') % (self.root, count)
7705
c55e68e8f256 notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents: 7658
diff changeset
   417
            else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   418
                s = ctx.description().lstrip().split(b'\n', 1)[0].rstrip()
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   419
                subject = b'%s: %s' % (self.root, s)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   420
        maxsubject = int(self.ui.config(b'notify', b'maxsubject'))
13202
d83566f4453b notify: use util.ellipsis() to truncate long subject
Yuya Nishihara <yuya@tcha.org>
parents: 10282
diff changeset
   421
        if maxsubject:
37087
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36636
diff changeset
   422
            subject = stringutil.ellipsis(subject, maxsubject)
40304
f6ef89cf8234 notify: a ton of encoding dancing to deal with the email module
Augie Fackler <augie@google.com>
parents: 40290
diff changeset
   423
        msg[r'Subject'] = encoding.strfromlocal(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   424
            mail.headencode(self.ui, subject, self.charsets, self.test)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   425
        )
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   426
7705
c55e68e8f256 notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents: 7658
diff changeset
   427
        # try to make message have proper sender
c55e68e8f256 notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents: 7658
diff changeset
   428
        if not sender:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   429
            sender = self.ui.config(b'email', b'from') or self.ui.username()
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   430
        if b'@' not in sender or b'@localhost' in sender:
7705
c55e68e8f256 notify: remove subfunctions that are called only once
Christian Ebert <blacktrash@gmx.net>
parents: 7658
diff changeset
   431
            sender = self.fixmail(sender)
40304
f6ef89cf8234 notify: a ton of encoding dancing to deal with the email module
Augie Fackler <augie@google.com>
parents: 40290
diff changeset
   432
        msg[r'From'] = encoding.strfromlocal(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   433
            mail.addressencode(self.ui, sender, self.charsets, self.test)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   434
        )
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   435
40304
f6ef89cf8234 notify: a ton of encoding dancing to deal with the email module
Augie Fackler <augie@google.com>
parents: 40290
diff changeset
   436
        msg[r'X-Hg-Notification'] = r'changeset %s' % ctx
f6ef89cf8234 notify: a ton of encoding dancing to deal with the email module
Augie Fackler <augie@google.com>
parents: 40290
diff changeset
   437
        if not msg[r'Message-Id']:
42910
d26a6706b070 notify: add option for deterministic message-id generation
Joerg Sonnenberger <joerg@bec.de>
parents: 41426
diff changeset
   438
            msg[r'Message-Id'] = messageid(ctx, self.domain, self.messageidseed)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   439
        msg[r'To'] = encoding.strfromlocal(b', '.join(sorted(subs)))
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   440
43322
7d912413a3ae py3: use as_bytes() method of EmailMessage
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 43164
diff changeset
   441
        msgtext = msg.as_bytes() if pycompat.ispy3 else msg.as_string()
7498
64840fcb79e1 notify: no charset conversion when testing
Christian Ebert <blacktrash@gmx.net>
parents: 7369
diff changeset
   442
        if self.test:
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   443
            self.ui.write(msgtext)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   444
            if not msgtext.endswith(b'\n'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   445
                self.ui.write(b'\n')
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   446
        else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   447
            self.ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   448
                _(b'notify: sending %d subscribers %d changes\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   449
                % (len(subs), count)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   450
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   451
            mail.sendmail(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   452
                self.ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   453
                stringutil.email(msg[r'From']),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   454
                subs,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   455
                msgtext,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   456
                mbox=self.mbox,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   457
            )
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   458
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
   459
    def diff(self, ctx, ref=None):
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
   460
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   461
        maxdiff = int(self.ui.config(b'notify', b'maxdiff'))
13878
a8d13ee0ce68 misc: replace .parents()[0] with p1()
Matt Mackall <mpm@selenic.com>
parents: 13202
diff changeset
   462
        prev = ctx.p1().node()
24306
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 23454
diff changeset
   463
        if ref:
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 23454
diff changeset
   464
            ref = ref.node()
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 23454
diff changeset
   465
        else:
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 23454
diff changeset
   466
            ref = ctx.node()
38070
d1134ca5b1a3 notify: add option to include function names in the diff output
Joerg Sonnenberger <joerg@bec.de>
parents: 37795
diff changeset
   467
        diffopts = patch.diffallopts(self.ui)
d1134ca5b1a3 notify: add option to include function names in the diff output
Joerg Sonnenberger <joerg@bec.de>
parents: 37795
diff changeset
   468
        diffopts.showfunc = self.showfunc
d1134ca5b1a3 notify: add option to include function names in the diff output
Joerg Sonnenberger <joerg@bec.de>
parents: 37795
diff changeset
   469
        chunks = patch.diff(self.repo, prev, ref, opts=diffopts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   470
        difflines = b''.join(chunks).splitlines()
6979
a3fd4aa154af notify: fix diffstat printing
divy@chelsio.com
parents: 6974
diff changeset
   471
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   472
        if self.ui.configbool(b'notify', b'diffstat'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   473
            maxdiffstat = int(self.ui.config(b'notify', b'maxdiffstat'))
3096
f422c8265ae5 Add support for diffstat in commit emails, and move diffstat from
Matt Doar <matt@xensource.com>
parents: 3017
diff changeset
   474
            s = patch.diffstat(difflines)
4077
1305ba7dee88 Prevent type exception on concatenation if diffstat returns None.
Sean Dague <sean@dague.net>
parents: 3739
diff changeset
   475
            # s may be nil, don't include the header if it is
1305ba7dee88 Prevent type exception on concatenation if diffstat returns None.
Sean Dague <sean@dague.net>
parents: 3739
diff changeset
   476
            if s:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   477
                if maxdiffstat >= 0 and s.count(b"\n") > maxdiffstat + 1:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   478
                    s = s.split(b"\n")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   479
                    msg = _(b'\ndiffstat (truncated from %d to %d lines):\n\n')
37777
a4cac7b0ea4f notify: add maxdiffstat option to truncate long file lists
Joerg Sonnenberger <joerg@bec.de>
parents: 37087
diff changeset
   480
                    self.ui.write(msg % (len(s) - 2, maxdiffstat))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   481
                    self.ui.write(b"\n".join(s[:maxdiffstat] + s[-2:]))
37777
a4cac7b0ea4f notify: add maxdiffstat option to truncate long file lists
Joerg Sonnenberger <joerg@bec.de>
parents: 37087
diff changeset
   482
                else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   483
                    self.ui.write(_(b'\ndiffstat:\n\n%s') % s)
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
   484
6305
e8d447d91cdb notify: print diffstat even if maxline == 0
Benoît Allard <benoit@aeteurope.nl>
parents: 6229
diff changeset
   485
        if maxdiff == 0:
e8d447d91cdb notify: print diffstat even if maxline == 0
Benoît Allard <benoit@aeteurope.nl>
parents: 6229
diff changeset
   486
            return
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
   487
        elif maxdiff > 0 and len(difflines) > maxdiff:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   488
            msg = _(b'\ndiffs (truncated from %d to %d lines):\n\n')
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
   489
            self.ui.write(msg % (len(difflines), maxdiff))
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   490
            difflines = difflines[:maxdiff]
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   491
        elif difflines:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   492
            self.ui.write(_(b'\ndiffs (%d lines):\n\n') % len(difflines))
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
   493
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   494
        self.ui.write(b"\n".join(difflines))
2201
f15056b29472 patch queue: notify.patch
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
   495
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   496
2230
332950340788 localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2225
diff changeset
   497
def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   498
    '''send email notifications to interested subscribers.
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   499
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   500
    if used as changegroup hook, send one email for all changesets in
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   501
    changegroup. else send one email per changeset.'''
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
   502
2203
9569eea1707c add email notification hook. hook written in python.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2201
diff changeset
   503
    n = notifier(ui, repo, hooktype)
37794
04d648b53e3e notify: access the initial revision on an unfiltered repository (issue5821)
Boris Feld <boris.feld@octobus.net>
parents: 37793
diff changeset
   504
    ctx = repo.unfiltered()[node]
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
   505
2329
90368f89340a notify: add debug output. do not fail if no config file.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2326
diff changeset
   506
    if not n.subs:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   507
        ui.debug(b'notify: no subscribers to repository %s\n' % n.root)
2329
90368f89340a notify: add debug output. do not fail if no config file.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2326
diff changeset
   508
        return
90368f89340a notify: add debug output. do not fail if no config file.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2326
diff changeset
   509
    if n.skipsource(source):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   510
        ui.debug(b'notify: changes have source "%s" - skipping\n' % source)
2230
332950340788 localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2225
diff changeset
   511
        return
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
   512
3739
16f8e7d1dd54 fix notify with new ui buffering
Matt Mackall <mpm@selenic.com>
parents: 3679
diff changeset
   513
    ui.pushbuffer()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   514
    data = b''
9516
f8048c334066 notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents: 9487
diff changeset
   515
    count = 0
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   516
    author = b''
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   517
    if hooktype == b'changegroup' or hooktype == b'outgoing':
37793
a07fab68621f notify: use changelog API to iterate over revision number (issue5821)
Boris Feld <boris.feld@octobus.net>
parents: 37777
diff changeset
   518
        for rev in repo.changelog.revs(start=ctx.rev()):
9516
f8048c334066 notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents: 9487
diff changeset
   519
            if n.node(repo[rev]):
f8048c334066 notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents: 9487
diff changeset
   520
                count += 1
15654
2a7fa7c641d8 notify: change behavior of "changegroup" hook
Nikolaus Schueler <nikolaus.schueler@lantiq.com>
parents: 15561
diff changeset
   521
                if not author:
2a7fa7c641d8 notify: change behavior of "changegroup" hook
Nikolaus Schueler <nikolaus.schueler@lantiq.com>
parents: 15561
diff changeset
   522
                    author = repo[rev].user()
9516
f8048c334066 notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents: 9487
diff changeset
   523
            else:
f8048c334066 notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents: 9487
diff changeset
   524
                data += ui.popbuffer()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   525
                ui.note(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   526
                    _(b'notify: suppressing notification for merge %d:%s\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   527
                    % (rev, repo[rev].hex()[:12])
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   528
                )
9516
f8048c334066 notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents: 9487
diff changeset
   529
                ui.pushbuffer()
f8048c334066 notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents: 9487
diff changeset
   530
        if count:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   531
            n.diff(ctx, repo[b'tip'])
37795
68748c2c761b notify: only notify for non-filtered revision
Boris Feld <boris.feld@octobus.net>
parents: 37794
diff changeset
   532
    elif ctx.rev() in repo:
9516
f8048c334066 notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents: 9487
diff changeset
   533
        if not n.node(ctx):
f8048c334066 notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents: 9487
diff changeset
   534
            ui.popbuffer()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   535
            ui.note(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   536
                _(b'notify: suppressing notification for merge %d:%s\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   537
                % (ctx.rev(), ctx.hex()[:12])
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   538
            )
9516
f8048c334066 notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents: 9487
diff changeset
   539
            return
f8048c334066 notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents: 9487
diff changeset
   540
        count += 1
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
   541
        n.diff(ctx)
26503
5a84a453b503 notify: fix fromauthor setting for 'incoming' hook type (issue4194)
Bruce Cran <bruce.cran@gmail.com>
parents: 25660
diff changeset
   542
        if not author:
5a84a453b503 notify: fix fromauthor setting for 'incoming' hook type (issue4194)
Bruce Cran <bruce.cran@gmail.com>
parents: 25660
diff changeset
   543
            author = ctx.user()
7726
2486980fe211 notify: use contexts more pervasively
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7705
diff changeset
   544
9516
f8048c334066 notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents: 9487
diff changeset
   545
    data += ui.popbuffer()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   546
    fromauthor = ui.config(b'notify', b'fromauthor')
15654
2a7fa7c641d8 notify: change behavior of "changegroup" hook
Nikolaus Schueler <nikolaus.schueler@lantiq.com>
parents: 15561
diff changeset
   547
    if author and fromauthor:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   548
        data = b'\n'.join([b'From: %s' % author, data])
15654
2a7fa7c641d8 notify: change behavior of "changegroup" hook
Nikolaus Schueler <nikolaus.schueler@lantiq.com>
parents: 15561
diff changeset
   549
9516
f8048c334066 notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents: 9487
diff changeset
   550
    if count:
f8048c334066 notify: permit suppression of merge changeset notification
David Champion <dgc@uchicago.edu>
parents: 9487
diff changeset
   551
        n.send(ctx, count, data)
42910
d26a6706b070 notify: add option for deterministic message-id generation
Joerg Sonnenberger <joerg@bec.de>
parents: 41426
diff changeset
   552
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   553
42910
d26a6706b070 notify: add option for deterministic message-id generation
Joerg Sonnenberger <joerg@bec.de>
parents: 41426
diff changeset
   554
def messageid(ctx, domain, messageidseed):
d26a6706b070 notify: add option for deterministic message-id generation
Joerg Sonnenberger <joerg@bec.de>
parents: 41426
diff changeset
   555
    if domain and messageidseed:
d26a6706b070 notify: add option for deterministic message-id generation
Joerg Sonnenberger <joerg@bec.de>
parents: 41426
diff changeset
   556
        host = domain
d26a6706b070 notify: add option for deterministic message-id generation
Joerg Sonnenberger <joerg@bec.de>
parents: 41426
diff changeset
   557
    else:
d26a6706b070 notify: add option for deterministic message-id generation
Joerg Sonnenberger <joerg@bec.de>
parents: 41426
diff changeset
   558
        host = encoding.strtolocal(socket.getfqdn())
d26a6706b070 notify: add option for deterministic message-id generation
Joerg Sonnenberger <joerg@bec.de>
parents: 41426
diff changeset
   559
    if messageidseed:
d26a6706b070 notify: add option for deterministic message-id generation
Joerg Sonnenberger <joerg@bec.de>
parents: 41426
diff changeset
   560
        messagehash = hashlib.sha512(ctx.hex() + messageidseed)
43164
c32531444cdc notify: cast hash to bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43117
diff changeset
   561
        messageid = b'<hg.%s@%s>' % (
c32531444cdc notify: cast hash to bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43117
diff changeset
   562
            pycompat.sysbytes(messagehash.hexdigest()[:64]),
c32531444cdc notify: cast hash to bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43117
diff changeset
   563
            host,
c32531444cdc notify: cast hash to bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43117
diff changeset
   564
        )
42910
d26a6706b070 notify: add option for deterministic message-id generation
Joerg Sonnenberger <joerg@bec.de>
parents: 41426
diff changeset
   565
    else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   566
        messageid = b'<hg.%s.%d.%d@%s>' % (
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   567
            ctx,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   568
            int(time.time()),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   569
            hash(ctx.repo().root),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   570
            host,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42910
diff changeset
   571
        )
42910
d26a6706b070 notify: add option for deterministic message-id generation
Joerg Sonnenberger <joerg@bec.de>
parents: 41426
diff changeset
   572
    return encoding.strfromlocal(messageid)