Staging
v0.5.1
https://foss.heptapod.net/mercurial/hgview
Revision 1ddc87097b45555523fd8b8d18874aecdee85d2f authored by Alain Leufroy on 28 May 2013, 10:34:27 UTC, committed by Alain Leufroy on 28 May 2013, 10:34:27 UTC
We were decoding strings for changeset description and file data only.  But we
also have to decode all all meta-information from Hg repo (a.k.a. usernames,
bookmarks, tags, branches, filenames).

String are decoded just at rendering times. Data are kept binary string for
other operation (eg: comparing filenames).

We use the ``hgviewlib.util.tounicode`` function everywhere now.

We also missed using utf-8 for Scintilla.

:Fix initiated by: Юрий Мандрик.

.. note:: We try to decode using utf8, iso-8859-15 and cp1252 (in this order)
          using the first that successfully decode the string. If all fail we
          use utf8 with ``replace`` strategy.

test case used::

    hg init cyrillic
    cd cyrillic
    hg branch 'ЖЗИЙФ'
    echo 'ЖЗИЙФ' > ЖЗИЙФ
    hg add ЖЗИЙФ
    hg ci -m 'ЖЗИЙФ' -u 'ЖЗИЙФ'
    hg bookmark 'ЖЗИЙФЖЗИЙФ'
    hg tag 'ЖЗИЙФ'
    hg mv 'ЖЗИЙФ' 'ЖЗИЙФЖЗИЙФ'
    hg ci -m 'move'
    echo 'hello' > ЖЗИЙФЖЗИЙФ
    hg ci -m 'back to ascii'
    hg rm ЖЗИЙФЖЗИЙФ
    hg ci -m 'remove'
1 parent d42a956
Raw File
Tip revision: 1ddc87097b45555523fd8b8d18874aecdee85d2f authored by Alain Leufroy on 28 May 2013, 10:34:27 UTC
[qt] full support for unicode with utf-8 encoding (closes #142378)
Tip revision: 1ddc870
hgview.py
# hgview: visual mercurial graphlog browser in PyQt4
#
# Copyright 2008-2010 Logilab
#
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.

'''browse the repository in a(n other) graphical way

The hgview extension allows browsing the history of a repository in a
graphical way. It requires PyQt4 with QScintilla.
'''

testedwith = '2.4'

buglink = 'https://www.logilab.org/project/hgview'

import os
import os.path as osp
import stat
import imp
from optparse import Values
from mercurial import error, demandimport

execpath = osp.abspath(__file__)
#   resolve symbolic links
statinfo = os.lstat(execpath)
if stat.S_ISLNK(statinfo.st_mode):
    execpath = join(osp.dirname(execpath), os.readlink(execpath))
    execpath = osp.abspath(execpath)
# if standalone, import manually
setuppath = osp.join(osp.dirname(osp.dirname(execpath)), 'setup.py')
if osp.exists(setuppath): # standalone if setup.py found in src dir
    hgviewlibpath = osp.join(osp.dirname(osp.dirname(execpath)), 'hgviewlib')
    hgviewlibpath = osp.abspath(hgviewlibpath)
    imp.load_package('hgviewlib', hgviewlibpath)

# every command must take a ui and and repo as arguments.
# opts is a dict where you can find other command line flags
#
# Other parameters are taken in order from items on the command line that
# don't start with a dash.  If no default value is given in the parameter list,
# they are required.

def start_hgview(ui, repo, *pats, **opts):
    # WARNING, this docstring is superseeded programmatically 
    """
start hgview log viewer
=======================

    This command will launch the hgview log navigator, allowing to
    visually browse in the hg graph log, search in logs, and display
    diff between arbitrary revisions of a file.

    If a filename is given, launch the filelog diff viewer for this file, 
    and with the '-n' option, launch the filelog navigator for the file.

    With the '-r' option, launch the manifest viewer for the given revision.

    """
    ### 2.5 compat
    # We ensure here that we work on unfiltered repo in all case. Unfiltered
    # repo are repo has we know them now.
    repo = getattr(repo, 'unfiltered', lambda: repo)()

    # If this user has a username validation hook enabled,
    # it could conflict with hgview because both will try to
    # allocate a QApplication, and PyQt doesn't deal well
    # with two app instances running under the same context.
    # To prevent this, we run the hook early before hgview
    # allocates the app
    try:
        from hgconf.uname import hook
        hook(ui, repo)
    except ImportError:
        pass

    from hgviewlib.application import start
    def fnerror(text):
        """process errors"""
        raise(error.Abort(text))
    options = Values(opts)
    start(repo, options, pats, fnerror)

import hgviewlib

# note: ``import hgviewlib.hgviewhelp`` is incompatible with standalone
#       because of the lazy import
from hgviewlib.hgviewhelp import long_help_msg
start_hgview.__doc__ = long_help_msg

cmdtable = {
    "^hgview|hgv|qv": (start_hgview,
                       [('n', 'navigate', False, '(with filename) start in navigation mode'),
                        ('r', 'rev', '', 'start in manifest navigation mode at rev R'),
                        ('s', 'start', '', 'show only graph from rev S'),
                        ('I', 'interface', '', 'GUI interface to use (among "qt", "raw" and "curses"')
                        ],
            "hg hgview [options] [filename]"),
}

back to top