[hg patches] Dedicate a module to patch Mercurial (closes #75296)

authorAlain Leufroy <alain.leufroy@logilab.fr>
changeset80a177693edc
branchdefault
phasepublic
hiddenno
parent revision#b7d8554f52ea [curses] fancier graph highlighting for nodes (imrpove #79263)
child revision#06ee39817550 [core] mercurial 2.0 support (closes #84549)
files modified by this revision
hgviewlib/__init__.py
hgviewlib/hggraph.py
hgviewlib/hgpatches/__init__.py
hgviewlib/hgpatches/scmutil.py
hgviewlib/util.py
# HG changeset patch
# User Alain Leufroy <alain.leufroy@logilab.fr>
# Date 1322143288 -3600
# Thu Nov 24 15:01:28 2011 +0100
# Node ID 80a177693edc167b09feb7ec8b42a566f3519dc9
# Parent b7d8554f52ea5d8cea3cc029092e2907410c21a1
[hg patches] Dedicate a module to patch Mercurial (closes #75296)

diff --git a/hgviewlib/__init__.py b/hgviewlib/__init__.py
@@ -18,12 +18,5 @@
1  Its purpose is similar to the hgk tool of mercurial, and it has been
2  written with efficiency in mind when dealing with big repositories
3  (it can happily be used to browse Linux kernel source code
4  repository).
5  """
6 -
7 -# monkey patch to support older hg versions
8 -from mercurial import changelog, filelog
9 -if not hasattr(changelog.changelog, '__len__'):
10 -    changelog.changelog.__len__ = changelog.changelog.count
11 -if not hasattr(filelog.filelog, '__len__'):
12 -    filelog.filelog.__len__ = filelog.filelog.count
diff --git a/hgviewlib/hggraph.py b/hgviewlib/hggraph.py
@@ -25,11 +25,11 @@
13  from itertools import chain
14 
15  from mercurial.node import nullrev
16  from mercurial import patch, util, match, error, hg
17 
18 -import hgviewlib # force apply monkeypatches
19 +import hgviewlib.hgpatches # force apply patches to mercurial
20  from hgviewlib.util import tounicode, isbfile
21  from hgviewlib.config import HgConfig
22 
23  def diff(repo, ctx1, ctx2=None, files=None):
24      """
diff --git a/hgviewlib/hgpatches/__init__.py b/hgviewlib/hgpatches/__init__.py
@@ -0,0 +1,25 @@
25 +# Copyright (c) 2003-2011 LOGILAB S.A. (Paris, FRANCE).
26 +# http://www.logilab.fr/ -- mailto:contact@logilab.fr
27 +#
28 +# This program is free software; you can redistribute it and/or modify it under
29 +# the terms of the GNU General Public License as published by the Free Software
30 +# Foundation; either version 2 of the License, or (at your option) any later
31 +# version.
32 +#
33 +# This program is distributed in the hope that it will be useful, but WITHOUT
34 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
35 +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
36 +#
37 +# You should have received a copy of the GNU General Public License along with
38 +# this program; if not, write to the Free Software Foundation, Inc.,
39 +# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
40 +"""
41 +This modules contains monkey patches for Mercurial allowing hgview to support
42 +older versions
43 +"""
44 +
45 +from mercurial import changelog, filelog
46 +if not hasattr(changelog.changelog, '__len__'):
47 +    changelog.changelog.__len__ = changelog.changelog.count
48 +if not hasattr(filelog.filelog, '__len__'):
49 +    filelog.filelog.__len__ = filelog.filelog.count
diff --git a/hgviewlib/hgpatches/scmutil.py b/hgviewlib/hgpatches/scmutil.py
@@ -0,0 +1,26 @@
50 +# Copyright (c) 2003-2011 LOGILAB S.A. (Paris, FRANCE).
51 +# http://www.logilab.fr/ -- mailto:contact@logilab.fr
52 +#
53 +# This program is free software; you can redistribute it and/or modify it under
54 +# the terms of the GNU General Public License as published by the Free Software
55 +# Foundation; either version 2 of the License, or (at your option) any later
56 +# version.
57 +#
58 +# This program is distributed in the hope that it will be useful, but WITHOUT
59 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
60 +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
61 +#
62 +# You should have received a copy of the GNU General Public License along with
63 +# this program; if not, write to the Free Software Foundation, Inc.,
64 +# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
65 +"""
66 +
67 +"""
68 +
69 +try:
70 +    from mercurial.scmutil import match
71 +except ImportError:
72 +    from mercurial import cmdutil
73 +    def match(ctx, *args, **kwargs):
74 +        cmdutil.match(ctx._repo, *args, **kwargs)
75 +
diff --git a/hgviewlib/util.py b/hgviewlib/util.py
@@ -10,10 +10,12 @@
76  """
77  import os
78  import string
79  from mercurial import ui
80 
81 +from hgviewlib.hgpatches.scmutil import match
82 +
83  def tounicode(string):
84      """
85      Tries to convert s into a unicode string
86      """
87      for encoding in ('utf-8', 'iso-8859-15', 'cp1252'):
@@ -79,17 +81,11 @@
88      """return the path name of 'path' relative to repo's root at
89      revision rev;
90      path is relative to cwd
91      """
92      ctx = repo[rev]
93 -    try:
94 -        from mercurial.cmdutil import match as hg_match
95 -        filenames = list(ctx.walk(hg_match(repo, [path], {})))
96 -    except ImportError:
97 -        # XXX it seems this changed since hg 1.9
98 -        from mercurial.scmutil import match as hg_match
99 -        filenames = list(ctx.walk(hg_match(ctx, [path], {})))
100 +    filenames = list(ctx.walk(match(ctx, [path], {})))
101      if len(filenames) != 1 or filenames[0] not in ctx.manifest():
102          return None
103      else:
104          return filenames[0]
105