Mercurial > public > mercurial-scm > hg
comparison mercurial/cmdutil.py @ 20033:f962870712da
pathutil: tease out a new library to break an import cycle from canonpath use
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Wed, 06 Nov 2013 18:19:04 -0500 |
parents | b7f76db06dc0 |
children | 6d4fda48b4e3 |
comparison
equal
deleted
inserted
replaced
20032:175c6fd8cacc | 20033:f962870712da |
---|---|
8 from node import hex, nullid, nullrev, short | 8 from node import hex, nullid, nullrev, short |
9 from i18n import _ | 9 from i18n import _ |
10 import os, sys, errno, re, tempfile | 10 import os, sys, errno, re, tempfile |
11 import util, scmutil, templater, patch, error, templatekw, revlog, copies | 11 import util, scmutil, templater, patch, error, templatekw, revlog, copies |
12 import match as matchmod | 12 import match as matchmod |
13 import subrepo, context, repair, graphmod, revset, phases, obsolete | 13 import subrepo, context, repair, graphmod, revset, phases, obsolete, pathutil |
14 import changelog | 14 import changelog |
15 import bookmarks | 15 import bookmarks |
16 import lock as lockmod | 16 import lock as lockmod |
17 | 17 |
18 def parsealiases(cmd): | 18 def parsealiases(cmd): |
272 | 272 |
273 # abssrc: hgsep | 273 # abssrc: hgsep |
274 # relsrc: ossep | 274 # relsrc: ossep |
275 # otarget: ossep | 275 # otarget: ossep |
276 def copyfile(abssrc, relsrc, otarget, exact): | 276 def copyfile(abssrc, relsrc, otarget, exact): |
277 abstarget = scmutil.canonpath(repo.root, cwd, otarget) | 277 abstarget = pathutil.canonpath(repo.root, cwd, otarget) |
278 if '/' in abstarget: | 278 if '/' in abstarget: |
279 # We cannot normalize abstarget itself, this would prevent | 279 # We cannot normalize abstarget itself, this would prevent |
280 # case only renames, like a => A. | 280 # case only renames, like a => A. |
281 abspath, absname = abstarget.rsplit('/', 1) | 281 abspath, absname = abstarget.rsplit('/', 1) |
282 abstarget = repo.dirstate.normalize(abspath) + '/' + absname | 282 abstarget = repo.dirstate.normalize(abspath) + '/' + absname |
365 # dest ossep | 365 # dest ossep |
366 # srcs: list of (hgsep, hgsep, ossep, bool) | 366 # srcs: list of (hgsep, hgsep, ossep, bool) |
367 # return: function that takes hgsep and returns ossep | 367 # return: function that takes hgsep and returns ossep |
368 def targetpathfn(pat, dest, srcs): | 368 def targetpathfn(pat, dest, srcs): |
369 if os.path.isdir(pat): | 369 if os.path.isdir(pat): |
370 abspfx = scmutil.canonpath(repo.root, cwd, pat) | 370 abspfx = pathutil.canonpath(repo.root, cwd, pat) |
371 abspfx = util.localpath(abspfx) | 371 abspfx = util.localpath(abspfx) |
372 if destdirexists: | 372 if destdirexists: |
373 striplen = len(os.path.split(abspfx)[0]) | 373 striplen = len(os.path.split(abspfx)[0]) |
374 else: | 374 else: |
375 striplen = len(abspfx) | 375 striplen = len(abspfx) |
391 if matchmod.patkind(pat): | 391 if matchmod.patkind(pat): |
392 # a mercurial pattern | 392 # a mercurial pattern |
393 res = lambda p: os.path.join(dest, | 393 res = lambda p: os.path.join(dest, |
394 os.path.basename(util.localpath(p))) | 394 os.path.basename(util.localpath(p))) |
395 else: | 395 else: |
396 abspfx = scmutil.canonpath(repo.root, cwd, pat) | 396 abspfx = pathutil.canonpath(repo.root, cwd, pat) |
397 if len(abspfx) < len(srcs[0][0]): | 397 if len(abspfx) < len(srcs[0][0]): |
398 # A directory. Either the target path contains the last | 398 # A directory. Either the target path contains the last |
399 # component of the source path or it does not. | 399 # component of the source path or it does not. |
400 def evalpath(striplen): | 400 def evalpath(striplen): |
401 score = 0 | 401 score = 0 |
2063 if not opts.get('dry_run'): | 2063 if not opts.get('dry_run'): |
2064 def checkout(f): | 2064 def checkout(f): |
2065 fc = ctx[f] | 2065 fc = ctx[f] |
2066 repo.wwrite(f, fc.data(), fc.flags()) | 2066 repo.wwrite(f, fc.data(), fc.flags()) |
2067 | 2067 |
2068 audit_path = scmutil.pathauditor(repo.root) | 2068 audit_path = pathutil.pathauditor(repo.root) |
2069 for f in remove[0]: | 2069 for f in remove[0]: |
2070 if repo.dirstate[f] == 'a': | 2070 if repo.dirstate[f] == 'a': |
2071 repo.dirstate.drop(f) | 2071 repo.dirstate.drop(f) |
2072 continue | 2072 continue |
2073 audit_path(f) | 2073 audit_path(f) |