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,24 @@ 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) + else: + abspats.append(kindpat) + 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 @@ -39,14 +39,16 @@ Repo root-relaive vs. cwd-relative includes $ 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=on --include notinsubdir/path + $ hg sparse --config sparse.includereporootpaths=off --include **/path + $ hg sparse --config sparse.includereporootpaths=off --include path:abspath $ hg sparse [include] $TESTTMP/myrepo/hide hide - reporoot/path - subdir/cwd/path + notinsubdir/path + path:abspath + subdir/**/path [exclude] @@ -59,18 +61,20 @@ [include] $TESTTMP/myrepo/hide hide - reporoot/path - subdir/cwd/path + notinsubdir/path + path:abspath + subdir/**/path [exclude] $ cd subdir - $ hg sparse --delete cwd/path + $ hg sparse --delete **/path $ hg sparse [include] $TESTTMP/myrepo/hide hide - reporoot/path + notinsubdir/path + path:abspath [exclude]