##// END OF EJS Templates
some modernization cleanups, forward compatibility
Dirkjan Ochtman -
r8366:0bf00450 default
parent child Browse files
Show More
@@ -741,7 +741,7 b' class queue:'
741 elif user:
741 elif user:
742 p.write("From: " + user + "\n\n")
742 p.write("From: " + user + "\n\n")
743
743
744 if callable(msg):
744 if hasattr(msg, '__call__'):
745 msg = msg()
745 msg = msg()
746 commitmsg = msg and msg or ("[mq]: %s" % patchfn)
746 commitmsg = msg and msg or ("[mq]: %s" % patchfn)
747 n = repo.commit(commitfiles, commitmsg, user, date, match=match, force=True)
747 n = repo.commit(commitfiles, commitmsg, user, date, match=match, force=True)
@@ -23,7 +23,7 b' import os'
23 import stat
23 import stat
24 import urllib
24 import urllib
25 import urllib2
25 import urllib2
26 import rfc822
26 import email.utils
27
27
28 try:
28 try:
29 from cStringIO import StringIO
29 from cStringIO import StringIO
@@ -214,7 +214,7 b' class FileRangeHandler(urllib2.FileHandl'
214 localfile = urllib.url2pathname(file)
214 localfile = urllib.url2pathname(file)
215 stats = os.stat(localfile)
215 stats = os.stat(localfile)
216 size = stats[stat.ST_SIZE]
216 size = stats[stat.ST_SIZE]
217 modified = rfc822.formatdate(stats[stat.ST_MTIME])
217 modified = email.utils.formatdate(stats[stat.ST_MTIME])
218 mtype = mimetypes.guess_type(file)[0]
218 mtype = mimetypes.guess_type(file)[0]
219 if host:
219 if host:
220 host, port = urllib.splitport(host)
220 host, port = urllib.splitport(host)
@@ -1464,7 +1464,7 b' def help_(ui, name=None, with_version=Fa'
1464 # description
1464 # description
1465 if not doc:
1465 if not doc:
1466 doc = _("(no help text available)")
1466 doc = _("(no help text available)")
1467 if callable(doc):
1467 if hasattr(doc, '__call__'):
1468 doc = doc()
1468 doc = doc()
1469
1469
1470 ui.write("%s\n" % header)
1470 ui.write("%s\n" % header)
@@ -70,7 +70,7 b' def fancyopts(args, options, state, gnu='
70 # copy defaults to state
70 # copy defaults to state
71 if isinstance(default, list):
71 if isinstance(default, list):
72 state[name] = default[:]
72 state[name] = default[:]
73 elif callable(default):
73 elif hasattr(default, '__call__'):
74 state[name] = None
74 state[name] = None
75 else:
75 else:
76 state[name] = default
76 state[name] = default
@@ -21,7 +21,7 b' def _pythonhook(ui, repo, name, hname, f'
21
21
22 ui.note(_("calling hook %s: %s\n") % (hname, funcname))
22 ui.note(_("calling hook %s: %s\n") % (hname, funcname))
23 obj = funcname
23 obj = funcname
24 if not callable(obj):
24 if not hasattr(obj, '__call__'):
25 d = funcname.rfind('.')
25 d = funcname.rfind('.')
26 if d == -1:
26 if d == -1:
27 raise util.Abort(_('%s hook is invalid ("%s" not in '
27 raise util.Abort(_('%s hook is invalid ("%s" not in '
@@ -44,7 +44,7 b' def _pythonhook(ui, repo, name, hname, f'
44 raise util.Abort(_('%s hook is invalid '
44 raise util.Abort(_('%s hook is invalid '
45 '("%s" is not defined)') %
45 '("%s" is not defined)') %
46 (hname, funcname))
46 (hname, funcname))
47 if not callable(obj):
47 if not hasattr(obj, '__call__'):
48 raise util.Abort(_('%s hook is invalid '
48 raise util.Abort(_('%s hook is invalid '
49 '("%s" is not callable)') %
49 '("%s" is not callable)') %
50 (hname, funcname))
50 (hname, funcname))
@@ -74,7 +74,7 b' def _exthook(ui, repo, name, cmd, args, '
74
74
75 env = {}
75 env = {}
76 for k, v in args.iteritems():
76 for k, v in args.iteritems():
77 if callable(v):
77 if hasattr(v, '__call__'):
78 v = v()
78 v = v()
79 env['HG_' + k.upper()] = v
79 env['HG_' + k.upper()] = v
80
80
@@ -107,7 +107,7 b' def hook(ui, repo, name, throw=False, **'
107 for hname, cmd in ui.configitems('hooks'):
107 for hname, cmd in ui.configitems('hooks'):
108 if hname.split('.')[0] != name or not cmd:
108 if hname.split('.')[0] != name or not cmd:
109 continue
109 continue
110 if callable(cmd):
110 if hasattr(cmd, '__call__'):
111 r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r
111 r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r
112 elif cmd.startswith('python:'):
112 elif cmd.startswith('python:'):
113 if cmd.count(':') == 2:
113 if cmd.count(':') == 2:
@@ -263,16 +263,8 b' def manifestmerge(repo, p1, p2, pa, over'
263
263
264 return action
264 return action
265
265
266 def actioncmp(a1, a2):
266 def actionkey(a):
267 m1 = a1[1]
267 return a[1] == 'r' and -1 or 0, a
268 m2 = a2[1]
269 if m1 == m2:
270 return cmp(a1, a2)
271 if m1 == 'r':
272 return -1
273 if m2 == 'r':
274 return 1
275 return cmp(a1, a2)
276
268
277 def applyupdates(repo, action, wctx, mctx):
269 def applyupdates(repo, action, wctx, mctx):
278 "apply the merge action list to the working directory"
270 "apply the merge action list to the working directory"
@@ -281,7 +273,7 b' def applyupdates(repo, action, wctx, mct'
281 ms = mergestate(repo)
273 ms = mergestate(repo)
282 ms.reset(wctx.parents()[0].node())
274 ms.reset(wctx.parents()[0].node())
283 moves = []
275 moves = []
284 action.sort(actioncmp)
276 action.sort(key=actionkey)
285
277
286 # prescan for merges
278 # prescan for merges
287 for a in action:
279 for a in action:
@@ -89,7 +89,7 b' class engine(object):'
89 v = map[key]
89 v = map[key]
90 else:
90 else:
91 v = self.defaults.get(key, "")
91 v = self.defaults.get(key, "")
92 if callable(v):
92 if hasattr(v, '__call__'):
93 v = v(**map)
93 v = v(**map)
94 if format:
94 if format:
95 if not hasattr(v, '__iter__'):
95 if not hasattr(v, '__iter__'):
General Comments 0
You need to be logged in to leave comments. Login now