2354 --full is specified, in which case entire paths are used.''' |
2354 --full is specified, in which case entire paths are used.''' |
2355 |
2355 |
2356 def complete(path, acceptable): |
2356 def complete(path, acceptable): |
2357 dirstate = repo.dirstate |
2357 dirstate = repo.dirstate |
2358 spec = os.path.normpath(os.path.join(pycompat.getcwd(), path)) |
2358 spec = os.path.normpath(os.path.join(pycompat.getcwd(), path)) |
2359 rootdir = repo.root + os.sep |
2359 rootdir = repo.root + pycompat.ossep |
2360 if spec != repo.root and not spec.startswith(rootdir): |
2360 if spec != repo.root and not spec.startswith(rootdir): |
2361 return [], [] |
2361 return [], [] |
2362 if os.path.isdir(spec): |
2362 if os.path.isdir(spec): |
2363 spec += '/' |
2363 spec += '/' |
2364 spec = spec[len(rootdir):] |
2364 spec = spec[len(rootdir):] |
2365 fixpaths = pycompat.ossep != '/' |
2365 fixpaths = pycompat.ossep != '/' |
2366 if fixpaths: |
2366 if fixpaths: |
2367 spec = spec.replace(os.sep, '/') |
2367 spec = spec.replace(pycompat.ossep, '/') |
2368 speclen = len(spec) |
2368 speclen = len(spec) |
2369 fullpaths = opts['full'] |
2369 fullpaths = opts['full'] |
2370 files, dirs = set(), set() |
2370 files, dirs = set(), set() |
2371 adddir, addfile = dirs.add, files.add |
2371 adddir, addfile = dirs.add, files.add |
2372 for f, st in dirstate.iteritems(): |
2372 for f, st in dirstate.iteritems(): |
2373 if f.startswith(spec) and st[0] in acceptable: |
2373 if f.startswith(spec) and st[0] in acceptable: |
2374 if fixpaths: |
2374 if fixpaths: |
2375 f = f.replace('/', os.sep) |
2375 f = f.replace('/', pycompat.ossep) |
2376 if fullpaths: |
2376 if fullpaths: |
2377 addfile(f) |
2377 addfile(f) |
2378 continue |
2378 continue |
2379 s = f.find(os.sep, speclen) |
2379 s = f.find(pycompat.ossep, speclen) |
2380 if s >= 0: |
2380 if s >= 0: |
2381 adddir(f[:s]) |
2381 adddir(f[:s]) |
2382 else: |
2382 else: |
2383 addfile(f) |
2383 addfile(f) |
2384 return files, dirs |
2384 return files, dirs |