diff --git a/hgext3rd/sparse.py b/hgext3rd/sparse.py --- a/hgext3rd/sparse.py +++ b/hgext3rd/sparse.py @@ -9,7 +9,7 @@ """ from mercurial import util, cmdutil, extensions, context, dirstate, commands -from mercurial import localrepo, error, hg, registrar, scmutil +from mercurial import localrepo, error, hg, pathutil, registrar from mercurial import match as matchmod from mercurial import merge as mergemod from mercurial.node import nullid @@ -20,6 +20,8 @@ command = registrar.command(cmdtable) testedwith = 'ships-with-fb-hgext' +cwdrealtivepatkinds = ('glob', 'relpath') + def uisetup(ui): _setupupdates(ui) _setupcommit(ui) @@ -762,17 +764,22 @@ err = _('paths cannot be absolute') raise error.Abort(err) - if (not ui.configbool('sparse', 'includereporootpaths', False) - and (include or exclude or delete)): + adjustpats = ((include or exclude or delete) and + not ui.configbool('sparse', 'includereporootpaths', False)) + adjustpats |= ((enableprofile or disableprofile) and + not ui.configbool('sparse', 'enablereporootpaths', True)) + if adjustpats: # supplied file patterns should be treated as relative # to current working dir, so we need to convert them first - pats = scmutil.match(repo['.'], pats).files() - - if (not ui.configbool('sparse', 'enablereporootpaths', True) - and (enableprofile or disableprofile)): - # supplied file patterns should be treated as relative - # to current working dir, so we need to convert them first - pats = scmutil.match(repo['.'], pats).files() + root, cwd = repo.root, repo.getcwd() + abspats = [] + for kindpat in pats: + kind, pat = matchmod._patsplit(kindpat, None) + if kind in cwdrealtivepatkinds or kind is None: + ap = (kind + ':' if kind else '') +\ + pathutil.canonpath(root, cwd, pat) + abspats.append(ap) + pats = abspats oldstatus = repo.status() if include: diff --git a/tests/test-sparse.t b/tests/test-sparse.t --- a/tests/test-sparse.t +++ b/tests/test-sparse.t @@ -40,13 +40,13 @@ $ mkdir subdir $ cd subdir $ hg sparse --config sparse.includereporootpaths=on --include reporoot/path - $ hg sparse --config sparse.includereporootpaths=off --include cwd/path + $ hg sparse --config sparse.includereporootpaths=off --include **/path $ hg sparse [include] $TESTTMP/myrepo/hide hide reporoot/path - subdir/cwd/path + subdir/**/path [exclude] @@ -60,12 +60,12 @@ $TESTTMP/myrepo/hide hide reporoot/path - subdir/cwd/path + subdir/**/path [exclude] $ cd subdir - $ hg sparse --delete cwd/path + $ hg sparse --delete **/path $ hg sparse [include] $TESTTMP/myrepo/hide