Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.9, 0.9.1, and 0.9.1.1

hglib: workaround bundlerepo bug in Mercurial 1.3

Changeset 9e63fca4e8c4

Parent ba6403563d93

by Steve Borho

Changes to one file · Browse files at 9e63fca4e8c4 Showing diff from parent ba6403563d93 Diff from another changeset...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
 
 
 
 
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
 # hglib.py - Mercurial API wrappers for TortoiseHg  #  # Copyright 2007 Steve Borho <steve@borho.org>  #  # This software may be used and distributed according to the terms of the  # GNU General Public License version 2, incorporated herein by reference.    import os  import sys  import traceback  import shlib  import time    from mercurial.error import RepoError, ParseError, LookupError, RepoLookupError  from mercurial.error import UnknownCommand, AmbiguousCommand  from mercurial import hg, ui, util, extensions, commands, hook, match -from mercurial import dispatch, encoding, templatefilters +from mercurial import dispatch, encoding, templatefilters, bundlerepo  _encoding = encoding.encoding  _encodingmode = encoding.encodingmode  _fallbackencoding = encoding.fallbackencoding    from tortoisehg.util import paths  from tortoisehg.util.i18n import _  from tortoisehg.util.hgversion import hgversion    def tounicode(s):   """   Convert the encoding of string from MBCS to Unicode.     Based on mercurial.util.tolocal().   Return 'unicode' type string.   """   if isinstance(s, unicode):   return s   for e in ('utf-8', _encoding):   try:   return s.decode(e, 'strict')   except UnicodeDecodeError:   pass   return s.decode(_fallbackencoding, 'replace')    def toutf(s):   """   Convert the encoding of string from MBCS to UTF-8.     Return 'str' type string.   """   return tounicode(s).encode('utf-8')    def fromutf(s):   """   Convert the encoding of string from UTF-8 to MBCS     Return 'str' type string.   """   try:   return s.decode('utf-8').encode(_encoding)   except UnicodeDecodeError:   pass   except UnicodeEncodeError:   pass   return s.decode('utf-8').encode(_fallbackencoding)    _tabwidth = None  def gettabwidth(ui):   global _tabwidth   if _tabwidth is not None:   return _tabwidth   tabwidth = ui.config('tortoisehg', 'tabwidth')   try:   tabwidth = int(tabwidth)   if tabwidth < 1 or tabwidth > 16:   tabwidth = 0   except (ValueError, TypeError):   tabwidth = 0   _tabwidth = tabwidth   return tabwidth    _maxdiff = None  def getmaxdiffsize(ui):   global _maxdiff   if _maxdiff is not None:   return _maxdiff   maxdiff = ui.config('tortoisehg', 'maxdiff')   try:   maxdiff = int(maxdiff)   if maxdiff < 1:   maxdiff = sys.maxint   except (ValueError, TypeError):   maxdiff = 1024 # 1MB by default   _maxdiff = maxdiff * 1024   return _maxdiff    def diffexpand(line):   'Expand tabs in a line of diff/patch text'   if _tabwidth is None:   gettabwidth(ui.ui())   if not _tabwidth or len(line) < 2:   return line   return line[0] + line[1:].expandtabs(_tabwidth)    def uiwrite(u, args):   '''   write args if there are buffers   returns True if the caller shall handle writing   '''   if u._buffers:   ui.ui.write(u, *args)   return False   return True    def invalidaterepo(repo): + if isinstance(repo, bundlerepo.bundlerepository): + # Work around a bug in hg-1.3. repo.invalidate() breaks + # overlay bundlerepos + return   repo.invalidate()   repo.dirstate.invalidate()   if 'mq' in repo.__dict__: #do not create if it does not exist   repo.mq.invalidate()    def canonpaths(list):   'Get canonical paths (relative to root) for list of files'   # This is a horrible hack. Please remove this when HG acquires a   # decent case-folding solution.   canonpats = []   cwd = os.getcwd()   root = paths.find_root(cwd)   for f in list:   try:   canonpats.append(util.canonpath(root, cwd, f))   except util.Abort:   # Attempt to resolve case folding conflicts.   fu = f.upper()   cwdu = cwd.upper()   if fu.startswith(cwdu):   canonpats.append(util.canonpath(root, cwd, f[len(cwd+os.sep):]))   else:   # May already be canonical   canonpats.append(f)   return canonpats    def normpats(pats):   'Normalize file patterns'   normpats = []   for pat in pats:   kind, p = match._patsplit(pat, None)   if kind:   normpats.append(pat)   else:   if '[' in p or '{' in p or '*' in p or '?' in p:   normpats.append('glob:' + p)   else:   normpats.append('path:' + p)   return normpats      def mergetools(ui, values=None):   'returns the configured merge tools and the internal ones'   if values == None:   values = []   from mercurial import filemerge   for key, value in ui.configitems('merge-tools'):   t = key.split('.')[0]   if t not in values:   # Ensure the tool is installed   if filemerge._findtool(ui, t):   values.append(t)   values.append('internal:merge')   values.append('internal:prompt')   values.append('internal:dump')   values.append('internal:local')   values.append('internal:other')   values.append('internal:fail')   return values      def hgcmd_toq(q, *args):   '''   Run an hg command in a background thread, pipe all output to a Queue   object. Assumes command is completely noninteractive.   '''   class Qui(ui.ui):   def __init__(self, src=None):   super(Qui, self).__init__(src)   self.setconfig('ui', 'interactive', 'off')     def write(self, *args):   if uiwrite(self, args):   for a in args:   q.put(str(a))   u = Qui()   for k, v in u.configitems('defaults'):   u.setconfig('defaults', k, '')   return dispatch._dispatch(u, list(args))    def displaytime(date):   return util.datestr(date, '%Y-%m-%d %H:%M:%S %1%2')    def utctime(date):   return time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(date[0]))    def username(user):   author = templatefilters.person(user)   if not author:   author = util.shortuser(user)   return author