hgext/interhg.py
author Matt Mackall <mpm@selenic.com>
Wed, 15 Aug 2007 16:10:24 -0500
changeset 5183 664a1c312972
parent 4818 0ac6b537893f
child 5288 18091102a633
permissions -rw-r--r--
fix-up references to repo.RepoError
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4818
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
     1
# interhg.py - interhg
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
     2
#
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
     3
# Copyright 2007 OHASHI Hideya <ohachige@gmail.com>
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
     4
#
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
     6
# of the GNU General Public License, incorporated herein by reference.
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
     7
#
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
     8
# The `interhg' Mercurial extension allows you to change changelog and
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
     9
# summary text just like InterWiki way.
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    10
#
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    11
# To enable this extension:
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    12
#
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    13
#   [extensions]
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    14
#   interhg =
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    15
#
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    16
# This is an example to link to a bug tracking system.
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    17
#
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    18
#   [interhg]
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    19
#   pat1 = s/issue(\d+)/ <a href="http:\/\/bts\/issue\1">issue\1<\/a> /
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    20
#
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    21
# You can add patterns to use pat2, pat3, ...
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    22
# For exapmle.
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    23
#
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    24
#   pat2 = s/(^|\s)#(\d+)\b/ <b>#\2<\/b> /
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    25
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    26
import re
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    27
from mercurial.hgweb import hgweb_mod
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    28
from mercurial import templater
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    29
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    30
orig_escape = templater.common_filters["escape"]
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    31
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    32
interhg_table = []
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    33
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    34
def interhg_escape(x):
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    35
    escstr = orig_escape(x)
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    36
    for pat in interhg_table:
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    37
        regexp = pat[0]
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    38
        format = pat[1]
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    39
        escstr = regexp.sub(format, escstr)
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    40
    return escstr
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    41
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    42
templater.common_filters["escape"] = interhg_escape
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    43
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    44
orig_refresh = hgweb_mod.hgweb.refresh
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    45
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    46
def interhg_refresh(self):
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    47
    interhg_table[:] = []
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    48
    num = 1
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    49
    while True:
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    50
        key = 'pat%d' % num
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    51
        pat = self.config('interhg', key)
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    52
        if pat == None:
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    53
            break
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    54
        pat = pat[2:-1]
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    55
        span = re.search(r'[^\\]/', pat).span()
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    56
        regexp = pat[:span[0] + 1]
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    57
        format = pat[span[1]:]
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    58
        format = re.sub(r'\\/', '/', format)
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    59
        regexp = re.compile(regexp)
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    60
        interhg_table.append((regexp, format))
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    61
        num += 1
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    62
    return orig_refresh(self)
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    63
0ac6b537893f interhg extension allows you to change changelog text like InterWiki.
OHASHI Hideya <ohachige@gmail.com>
parents:
diff changeset
    64
hgweb_mod.hgweb.refresh = interhg_refresh