##// END OF EJS Templates
move canonpath from util to scmutil
Adrian Buehlmann -
r13971:bfeaa88b default
parent child Browse files
Show More
@@ -18,7 +18,7 b' from mercurial.commands import templateo'
18 from mercurial.i18n import _
18 from mercurial.i18n import _
19 from mercurial.node import nullrev
19 from mercurial.node import nullrev
20 from mercurial import cmdutil, commands, extensions
20 from mercurial import cmdutil, commands, extensions
21 from mercurial import hg, util, graphmod
21 from mercurial import hg, scmutil, util, graphmod
22
22
23 ASCIIDATA = 'ASC'
23 ASCIIDATA = 'ASC'
24
24
@@ -250,7 +250,7 b' def graphlog(ui, repo, path=None, **opts'
250 return
250 return
251
251
252 if path:
252 if path:
253 path = util.canonpath(repo.root, os.getcwd(), path)
253 path = scmutil.canonpath(repo.root, os.getcwd(), path)
254 if path: # could be reset in canonpath
254 if path: # could be reset in canonpath
255 revdag = graphmod.filerevs(repo, path, start, stop, limit)
255 revdag = graphmod.filerevs(repo, path, start, stop, limit)
256 else:
256 else:
@@ -83,6 +83,7 b" like CVS' $Log$, are not supported. A ke"
83
83
84 from mercurial import commands, context, cmdutil, dispatch, filelog, extensions
84 from mercurial import commands, context, cmdutil, dispatch, filelog, extensions
85 from mercurial import localrepo, match, patch, templatefilters, templater, util
85 from mercurial import localrepo, match, patch, templatefilters, templater, util
86 from mercurial import scmutil
86 from mercurial.hgweb import webcommands
87 from mercurial.hgweb import webcommands
87 from mercurial.i18n import _
88 from mercurial.i18n import _
88 import os, re, shutil, tempfile
89 import os, re, shutil, tempfile
@@ -619,8 +620,8 b' def reposetup(ui, repo):'
619 expansion. '''
620 expansion. '''
620 source = repo.dirstate.copied(dest)
621 source = repo.dirstate.copied(dest)
621 if 'l' in wctx.flags(source):
622 if 'l' in wctx.flags(source):
622 source = util.canonpath(repo.root, cwd,
623 source = scmutil.canonpath(repo.root, cwd,
623 os.path.realpath(source))
624 os.path.realpath(source))
624 return kwt.match(source)
625 return kwt.match(source)
625
626
626 candidates = [f for f in repo.dirstate.copies() if
627 candidates = [f for f in repo.dirstate.copies() if
@@ -429,7 +429,7 b' def copy(ui, repo, pats, opts, rename=Fa'
429 # relsrc: ossep
429 # relsrc: ossep
430 # otarget: ossep
430 # otarget: ossep
431 def copyfile(abssrc, relsrc, otarget, exact):
431 def copyfile(abssrc, relsrc, otarget, exact):
432 abstarget = util.canonpath(repo.root, cwd, otarget)
432 abstarget = scmutil.canonpath(repo.root, cwd, otarget)
433 reltarget = repo.pathto(abstarget, cwd)
433 reltarget = repo.pathto(abstarget, cwd)
434 target = repo.wjoin(abstarget)
434 target = repo.wjoin(abstarget)
435 src = repo.wjoin(abssrc)
435 src = repo.wjoin(abssrc)
@@ -497,7 +497,7 b' def copy(ui, repo, pats, opts, rename=Fa'
497 # return: function that takes hgsep and returns ossep
497 # return: function that takes hgsep and returns ossep
498 def targetpathfn(pat, dest, srcs):
498 def targetpathfn(pat, dest, srcs):
499 if os.path.isdir(pat):
499 if os.path.isdir(pat):
500 abspfx = util.canonpath(repo.root, cwd, pat)
500 abspfx = scmutil.canonpath(repo.root, cwd, pat)
501 abspfx = util.localpath(abspfx)
501 abspfx = util.localpath(abspfx)
502 if destdirexists:
502 if destdirexists:
503 striplen = len(os.path.split(abspfx)[0])
503 striplen = len(os.path.split(abspfx)[0])
@@ -523,7 +523,7 b' def copy(ui, repo, pats, opts, rename=Fa'
523 res = lambda p: os.path.join(dest,
523 res = lambda p: os.path.join(dest,
524 os.path.basename(util.localpath(p)))
524 os.path.basename(util.localpath(p)))
525 else:
525 else:
526 abspfx = util.canonpath(repo.root, cwd, pat)
526 abspfx = scmutil.canonpath(repo.root, cwd, pat)
527 if len(abspfx) < len(srcs[0][0]):
527 if len(abspfx) < len(srcs[0][0]):
528 # A directory. Either the target path contains the last
528 # A directory. Either the target path contains the last
529 # component of the source path or it does not.
529 # component of the source path or it does not.
@@ -7,7 +7,7 b''
7 # GNU General Public License version 2 or any later version.
7 # GNU General Public License version 2 or any later version.
8
8
9 import os, copy
9 import os, copy
10 from mercurial import match, patch, util, error, ui
10 from mercurial import match, patch, scmutil, error, ui
11 from mercurial.node import hex, nullid
11 from mercurial.node import hex, nullid
12
12
13 def up(p):
13 def up(p):
@@ -127,7 +127,7 b' def showbookmark(repo, tmpl, t1, node=nu'
127
127
128 def cleanpath(repo, path):
128 def cleanpath(repo, path):
129 path = path.lstrip('/')
129 path = path.lstrip('/')
130 return util.canonpath(repo.root, '', path)
130 return scmutil.canonpath(repo.root, '', path)
131
131
132 def changectx(repo, req):
132 def changectx(repo, req):
133 changeid = "tip"
133 changeid = "tip"
@@ -6,7 +6,7 b''
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 import re
8 import re
9 import util
9 import scmutil, util
10 from i18n import _
10 from i18n import _
11
11
12 class match(object):
12 class match(object):
@@ -269,7 +269,7 b' def _normalize(names, default, root, cwd'
269 pats = []
269 pats = []
270 for kind, name in [_patsplit(p, default) for p in names]:
270 for kind, name in [_patsplit(p, default) for p in names]:
271 if kind in ('glob', 'relpath'):
271 if kind in ('glob', 'relpath'):
272 name = util.canonpath(root, cwd, name, auditor)
272 name = scmutil.canonpath(root, cwd, name, auditor)
273 elif kind in ('relglob', 'path'):
273 elif kind in ('relglob', 'path'):
274 name = util.normpath(name)
274 name = util.normpath(name)
275 elif kind in ('listfile', 'listfile0'):
275 elif kind in ('listfile', 'listfile0'):
@@ -21,7 +21,8 b' class PatchError(Exception):'
21 # helper functions
21 # helper functions
22
22
23 def copyfile(src, dst, basedir):
23 def copyfile(src, dst, basedir):
24 abssrc, absdst = [util.canonpath(basedir, basedir, x) for x in [src, dst]]
24 abssrc, absdst = [scmutil.canonpath(basedir, basedir, x)
25 for x in [src, dst]]
25 if os.path.lexists(absdst):
26 if os.path.lexists(absdst):
26 raise util.Abort(_("cannot create %s: destination already exists") %
27 raise util.Abort(_("cannot create %s: destination already exists") %
27 dst)
28 dst)
@@ -120,3 +120,51 b' class opener(object):'
120 f.write(src)
120 f.write(src)
121 f.close()
121 f.close()
122 self._fixfilemode(dst)
122 self._fixfilemode(dst)
123
124 def canonpath(root, cwd, myname, auditor=None):
125 '''return the canonical path of myname, given cwd and root'''
126 if util.endswithsep(root):
127 rootsep = root
128 else:
129 rootsep = root + os.sep
130 name = myname
131 if not os.path.isabs(name):
132 name = os.path.join(root, cwd, name)
133 name = os.path.normpath(name)
134 if auditor is None:
135 auditor = util.path_auditor(root)
136 if name != rootsep and name.startswith(rootsep):
137 name = name[len(rootsep):]
138 auditor(name)
139 return util.pconvert(name)
140 elif name == root:
141 return ''
142 else:
143 # Determine whether `name' is in the hierarchy at or beneath `root',
144 # by iterating name=dirname(name) until that causes no change (can't
145 # check name == '/', because that doesn't work on windows). For each
146 # `name', compare dev/inode numbers. If they match, the list `rel'
147 # holds the reversed list of components making up the relative file
148 # name we want.
149 root_st = os.stat(root)
150 rel = []
151 while True:
152 try:
153 name_st = os.stat(name)
154 except OSError:
155 break
156 if util.samestat(name_st, root_st):
157 if not rel:
158 # name was actually the same as root (maybe a symlink)
159 return ''
160 rel.reverse()
161 name = os.path.join(*rel)
162 auditor(name)
163 return util.pconvert(name)
164 dirname, basename = os.path.split(name)
165 rel.append(basename)
166 if dirname == name:
167 break
168 name = dirname
169
170 raise util.Abort('%s not under root' % myname)
@@ -295,54 +295,6 b' def pathto(root, n1, n2):'
295 b.reverse()
295 b.reverse()
296 return os.sep.join((['..'] * len(a)) + b) or '.'
296 return os.sep.join((['..'] * len(a)) + b) or '.'
297
297
298 def canonpath(root, cwd, myname, auditor=None):
299 """return the canonical path of myname, given cwd and root"""
300 if endswithsep(root):
301 rootsep = root
302 else:
303 rootsep = root + os.sep
304 name = myname
305 if not os.path.isabs(name):
306 name = os.path.join(root, cwd, name)
307 name = os.path.normpath(name)
308 if auditor is None:
309 auditor = path_auditor(root)
310 if name != rootsep and name.startswith(rootsep):
311 name = name[len(rootsep):]
312 auditor(name)
313 return pconvert(name)
314 elif name == root:
315 return ''
316 else:
317 # Determine whether `name' is in the hierarchy at or beneath `root',
318 # by iterating name=dirname(name) until that causes no change (can't
319 # check name == '/', because that doesn't work on windows). For each
320 # `name', compare dev/inode numbers. If they match, the list `rel'
321 # holds the reversed list of components making up the relative file
322 # name we want.
323 root_st = os.stat(root)
324 rel = []
325 while True:
326 try:
327 name_st = os.stat(name)
328 except OSError:
329 break
330 if samestat(name_st, root_st):
331 if not rel:
332 # name was actually the same as root (maybe a symlink)
333 return ''
334 rel.reverse()
335 name = os.path.join(*rel)
336 auditor(name)
337 return pconvert(name)
338 dirname, basename = os.path.split(name)
339 rel.append(basename)
340 if dirname == name:
341 break
342 name = dirname
343
344 raise Abort('%s not under root' % myname)
345
346 _hgexecutable = None
298 _hgexecutable = None
347
299
348 def main_is_frozen():
300 def main_is_frozen():
General Comments 0
You need to be logged in to leave comments. Login now