view mercurial/help.py @ 9748:67e5d5a2f625

Sometimes pushing to an HTTP repo fails with a useless message. abort: 'https://.../.../' does not appear to be an hg repository! Ought to produce a better diagnostics on the client. With patched 1.3.1, observed to produce an Apache HTML error message (from cgitb) including the vital text: File ".../hgwebdir.cgi", line 70, in ? wsgicgi.launch(application) File "mercurial/hgweb/wsgicgi.py", line 68, in launch File "mercurial/hgweb/hgwebdir_mod.py", line 91, in __call__ File "mercurial/hgweb/hgwebdir_mod.py", line 148, in run_wsgi File "mercurial/hgweb/hgweb_mod.py", line 100, in run_wsgi File "mercurial/hgweb/protocol.py", line 156, in unbundle File "mercurial/localrepo.py", line 2031, in addchangegroup File "mercurial/revlog.py", line 1204, in addgroup LookupError: 00manifest.i@......: unknown parent Might also be helpful if server's hgweb_mod.run_wsgi caught unexpected errors and returned a well-formed error response including the stack trace. The client patch would still be useful in this case, because it would let you diagnose issues with HTTP proxy servers and so on.
author Jesse Glick <jesse.glick@sun.com>
date Sat, 17 Oct 2009 14:00:41 -0400
parents e2b1de5fee04
children b52f0f221325
line wrap: on
line source

# help.py - help data for mercurial
#
# Copyright 2006 Matt Mackall <mpm@selenic.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2, incorporated herein by reference.

from i18n import gettext, _
import sys, os
import extensions


def moduledoc(file):
    '''return the top-level python documentation for the given file

    Loosely inspired by pydoc.source_synopsis(), but rewritten to handle \'''
    as well as """ and to return the whole text instead of just the synopsis'''
    result = []

    line = file.readline()
    while line[:1] == '#' or not line.strip():
        line = file.readline()
        if not line: break

    start = line[:3]
    if start == '"""' or start == "'''":
        line = line[3:]
        while line:
            if line.rstrip().endswith(start):
                line = line.split(start)[0]
                if line:
                    result.append(line)
                break
            elif not line:
                return None # unmatched delimiter
            result.append(line)
            line = file.readline()
    else:
        return None

    return ''.join(result)

def listexts(header, exts, maxlength):
    '''return a text listing of the given extensions'''
    if not exts:
        return ''
    result = '\n%s\n\n' % header
    for name, desc in sorted(exts.iteritems()):
        result += ' %-*s %s\n' % (maxlength + 2, ':%s:' % name, desc)
    return result

def extshelp():
    doc = loaddoc('extensions')()

    exts, maxlength = extensions.enabled()
    doc += listexts(_('enabled extensions:'), exts, maxlength)

    exts, maxlength = extensions.disabled()
    doc += listexts(_('disabled extensions:'), exts, maxlength)

    return doc

def loaddoc(topic):
    """Return a delayed loader for help/topic.txt."""

    def loader():
        if hasattr(sys, 'frozen'):
            module = sys.executable
        else:
            module = __file__
        base = os.path.dirname(module)

        for dir in ('.', '..'):
            docdir = os.path.join(base, dir, 'help')
            if os.path.isdir(docdir):
                break

        path = os.path.join(docdir, topic + ".txt")
        return gettext(open(path).read())
    return loader

helptable = (
    (["dates"], _("Date Formats"), loaddoc('dates')),
    (["patterns"], _("File Name Patterns"), loaddoc('patterns')),
    (['environment', 'env'], _('Environment Variables'), loaddoc('environment')),
    (['revs', 'revisions'], _('Specifying Single Revisions'), loaddoc('revisions')),
    (['mrevs', 'multirevs'], _('Specifying Multiple Revisions'), loaddoc('multirevs')),
    (['diffs'], _('Diff Formats'), loaddoc('diffs')),
    (['templating', 'templates'], _('Template Usage'), loaddoc('templates')),
    (['urls'], _('URL Paths'), loaddoc('urls')),
    (["extensions"], _("Using additional features"), extshelp),
)