mirror of
https://github.com/facebook/sapling.git
synced 2024-12-27 23:22:02 +03:00
sparse: clean up path handling, making it platform agnostic
Summary: There is no need to strip path separators from the normalised path; normpath will never leave any. We also ensure that the path prefix we test ends in a path separator, to avoid matching on sibling paths that happen to share a prefix. Reviewed By: ryanmce Differential Revision: D7056649 fbshipit-source-id: 10b78a78ba44fbc8d9c05fb7ffd0ffd1c1496a67
This commit is contained in:
parent
73568fd07d
commit
42ac84e8cf
@ -9,7 +9,7 @@
|
||||
"""
|
||||
|
||||
from mercurial import util, cmdutil, extensions, context, dirstate, commands
|
||||
from mercurial import localrepo, error, hg, pathutil, registrar, patch
|
||||
from mercurial import localrepo, error, hg, pathutil, registrar, patch, pycompat
|
||||
from mercurial import match as matchmod
|
||||
from mercurial import merge as mergemod
|
||||
from mercurial.node import nullid
|
||||
@ -1202,26 +1202,26 @@ def _cwdlist(repo):
|
||||
"""
|
||||
ctx = repo['.']
|
||||
mf = ctx.manifest()
|
||||
cwd = util.normpath(os.getcwd())
|
||||
|
||||
# Get the root of the repo so that we remove the content of
|
||||
# the root from the current working directory
|
||||
root = repo.root
|
||||
if cwd.startswith(root):
|
||||
cwd = cwd[len(root):]
|
||||
else:
|
||||
raise error.Abort(_("the current working directory should begin " +
|
||||
"with the root %s") % root)
|
||||
cwd = util.normpath(pycompat.getcwd())
|
||||
cwd = os.path.relpath(cwd, root)
|
||||
cwd = '' if cwd == os.curdir else cwd + pycompat.ossep
|
||||
if cwd.startswith(os.pardir + pycompat.ossep):
|
||||
raise error.Abort(
|
||||
_("the current working directory should begin "
|
||||
"with the root %s") % root)
|
||||
|
||||
cwd = cwd.strip("/")
|
||||
sparsematch = repo.sparsematch(ctx.rev())
|
||||
checkedoutentries = set()
|
||||
allentries = set()
|
||||
cwdlength = len(cwd) + 1
|
||||
cwdlength = len(cwd)
|
||||
|
||||
for filepath in mf:
|
||||
if filepath.startswith(cwd):
|
||||
tail = filepath[cwdlength:] if cwdlength > 1 else filepath
|
||||
entryname = tail.split('/', 1)[0]
|
||||
entryname = filepath[cwdlength:].partition(pycompat.ossep)[0]
|
||||
|
||||
allentries.add(entryname)
|
||||
if sparsematch(filepath):
|
||||
|
@ -95,9 +95,6 @@ New errors are not allowed. Warnings are strongly discouraged.
|
||||
hgext/fastannotate/commands.py:43:
|
||||
> reldir = os.path.relpath(os.getcwd(), reporoot)
|
||||
use pycompat.getcwd instead (py3)
|
||||
hgext/fbsparse.py:1205:
|
||||
> cwd = util.normpath(os.getcwd())
|
||||
use pycompat.getcwd instead (py3)
|
||||
Skipping hgext/hgsql.py it has no-che?k-code (glob)
|
||||
Skipping hgext/hgsubversion/__init__.py it has no-che?k-code (glob)
|
||||
Skipping hgext/hgsubversion/compathacks.py it has no-che?k-code (glob)
|
||||
|
@ -354,7 +354,20 @@ Test --cwd-list
|
||||
$ hg sparse --cwd-list
|
||||
- bar
|
||||
foo
|
||||
$ cd ..
|
||||
|
||||
Make sure to match whole directory names, not prefixes
|
||||
|
||||
$ mkdir prefix prefixpostfix
|
||||
$ touch prefix/correct prefixpostfix/incorrect
|
||||
$ hg sparse -I prefix prefixpostfix
|
||||
$ hg addremove .
|
||||
adding prefix/correct
|
||||
adding prefixpostfix/incorrect
|
||||
$ hg ci -m 'subdirs'
|
||||
$ cd prefix
|
||||
$ hg sparse --cwd-list
|
||||
correct
|
||||
$ cd ../..
|
||||
|
||||
$ cd ..
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user