comparison mercurial/sparse.py @ 33685:e1c56486d1aa

sparse: treat paths as cwd-relative This commit makes it so sparse treats passed paths as CWD-relative, not repo-root-realive. This is a more intuitive behavior in my (and some other FB people's) opinion. This is breaking change however. My hope here is that since sparse is experimental, it's ok to introduce BCs. The reason (glob)s are needed in the test is this: in these two cases we do not supply path together with slashes, but `os.path.join` adds them, which means that under Windows they can be backslashes. To demonstrate this behavior, one could remove the (glob)s and run `./run-tests.py test-sparse.t` from MinGW's terminal on Windows.
author Kostia Balytskyi <ikostia@fb.com>
date Fri, 04 Aug 2017 05:38:22 -0700
parents 7dcb517122f9
children 81aebcc73beb
comparison
equal deleted inserted replaced
33684:2be0bf186950 33685:e1c56486d1aa
15 from .node import nullid 15 from .node import nullid
16 from . import ( 16 from . import (
17 error, 17 error,
18 match as matchmod, 18 match as matchmod,
19 merge as mergemod, 19 merge as mergemod,
20 pathutil,
20 pycompat, 21 pycompat,
21 scmutil, 22 scmutil,
22 util, 23 util,
23 ) 24 )
24 25
614 printchanges(repo.ui, opts, profilecount, includecount, excludecount, 615 printchanges(repo.ui, opts, profilecount, includecount, excludecount,
615 *fcounts) 616 *fcounts)
616 617
617 def updateconfig(repo, pats, opts, include=False, exclude=False, reset=False, 618 def updateconfig(repo, pats, opts, include=False, exclude=False, reset=False,
618 delete=False, enableprofile=False, disableprofile=False, 619 delete=False, enableprofile=False, disableprofile=False,
619 force=False): 620 force=False, usereporootpaths=False):
620 """Perform a sparse config update. 621 """Perform a sparse config update.
621 622
622 Only one of the actions may be performed. 623 Only one of the actions may be performed.
623 624
624 The new config is written out and a working directory refresh is performed. 625 The new config is written out and a working directory refresh is performed.
636 newexclude = set(oldexclude) 637 newexclude = set(oldexclude)
637 newprofiles = set(oldprofiles) 638 newprofiles = set(oldprofiles)
638 639
639 if any(os.path.isabs(pat) for pat in pats): 640 if any(os.path.isabs(pat) for pat in pats):
640 raise error.Abort(_('paths cannot be absolute')) 641 raise error.Abort(_('paths cannot be absolute'))
642
643 if not usereporootpaths:
644 # let's treat paths as relative to cwd
645 root, cwd = repo.root, repo.getcwd()
646 abspats = []
647 for kindpat in pats:
648 kind, pat = matchmod._patsplit(kindpat, None)
649 if kind in matchmod.cwdrelativepatternkinds or kind is None:
650 ap = (kind + ':' if kind else '') +\
651 pathutil.canonpath(root, cwd, pat)
652 abspats.append(ap)
653 else:
654 abspats.append(kindpat)
655 pats = abspats
641 656
642 if include: 657 if include:
643 newinclude.update(pats) 658 newinclude.update(pats)
644 elif exclude: 659 elif exclude:
645 newexclude.update(pats) 660 newexclude.update(pats)