##// END OF EJS Templates
Update util.py docstrings, fix walk test
mpm@selenic.com -
r1082:ce96e316 default
parent child Browse files
Show More
@@ -1,20 +1,27 b''
1 # util.py - utility functions and platform specfic implementations
2 #
3 # Copyright 2005 K. Thananchayan <thananck@yahoo.com>
4 #
5 # This software may be used and distributed according to the terms
6 # of the GNU General Public License, incorporated herein by reference.
1 """
2 util.py - Mercurial utility functions and platform specfic implementations
3
4 Copyright 2005 K. Thananchayan <thananck@yahoo.com>
5
6 This software may be used and distributed according to the terms
7 of the GNU General Public License, incorporated herein by reference.
8
9 This contains helper routines that are independent of the SCM core and hide
10 platform-specific details from the core.
11 """
7 12
8 13 import os, errno
9 14 from demandload import *
10 15 demandload(globals(), "re")
11 16
12 17 def binary(s):
18 """return true if a string is binary data using diff's heuristic"""
13 19 if s and '\0' in s[:4096]:
14 20 return True
15 21 return False
16 22
17 23 def unique(g):
24 """return the uniq elements of iterable g"""
18 25 seen = {}
19 26 for f in g:
20 27 if f not in seen:
@@ -86,6 +93,7 b' def pathto(n1, n2):'
86 93 return os.sep.join((['..'] * len(a)) + b)
87 94
88 95 def canonpath(root, cwd, myname):
96 """return the canonical path of myname, given cwd and root"""
89 97 rootsep = root + os.sep
90 98 name = myname
91 99 if not name.startswith(os.sep):
@@ -99,6 +107,33 b' def canonpath(root, cwd, myname):'
99 107 raise Abort('%s not under root' % myname)
100 108
101 109 def matcher(canonroot, cwd, names, inc, exc, head=''):
110 """build a function to match a set of file patterns
111
112 arguments:
113 canonroot - the canonical root of the tree you're matching against
114 cwd - the current working directory, if relevant
115 names - patterns to find
116 inc - patterns to include
117 exc - patterns to exclude
118 head - a regex to prepend to patterns to control whether a match is rooted
119
120 a pattern is one of:
121 're:<regex>'
122 'glob:<shellglob>'
123 'path:<explicit path>'
124 'relpath:<relative path>'
125 '<relative path>'
126
127 returns:
128 a 3-tuple containing
129 - list of explicit non-pattern names passed in
130 - a bool match(filename) function
131 - a bool indicating if any patterns were passed in
132
133 todo:
134 make head regex a rooted bool
135 """
136
102 137 def patkind(name):
103 138 for prefix in 're:', 'glob:', 'path:', 'relpath:':
104 139 if name.startswith(prefix): return name.split(':', 1)
@@ -175,6 +210,7 b' def system(cmd, errprefix=None):'
175 210 raise Abort(errmsg)
176 211
177 212 def rename(src, dst):
213 """forcibly rename a file"""
178 214 try:
179 215 os.rename(src, dst)
180 216 except:
@@ -204,7 +240,7 b' def _makelock_file(info, pathname):'
204 240 def _readlock_file(pathname):
205 241 return file(pathname).read()
206 242
207 # Platfor specific varients
243 # Platform specific variants
208 244 if os.name == 'nt':
209 245 nulldev = 'NUL:'
210 246
@@ -233,6 +269,7 b' else:'
233 269 nulldev = '/dev/null'
234 270
235 271 def is_exec(f, last):
272 """check whether a file is executable"""
236 273 return (os.stat(f).st_mode & 0100 != 0)
237 274
238 275 def set_exec(f, mode):
@@ -63,8 +63,8 b' f mammals/skunk mamma'
63 63 f mammals/Procyonidae/cacomistle mammals/Procyonidae/cacomistle
64 64 f mammals/Procyonidae/coatimundi mammals/Procyonidae/coatimundi
65 65 f mammals/Procyonidae/raccoon mammals/Procyonidae/raccoon
66 abort: .. not under repository root
67 abort: beans/../.. not under repository root
66 abort: .. not under root
67 abort: beans/../.. not under root
68 68 f fennel fennel
69 69 f fenugreek fenugreek
70 70 f fiddlehead fiddlehead
General Comments 0
You need to be logged in to leave comments. Login now