comparison mercurial/scmutil.py @ 41652:6a447a3d1bd0

addremove: pass around uipathfn and use instead of m.uipath() (API) Differential Revision: https://phab.mercurial-scm.org/D5903
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 07 Feb 2019 23:25:39 -0800
parents f8b18583049f
children 0a5a6675c86c
comparison
equal deleted inserted replaced
41651:b2df5dc3ebfb 41652:6a447a3d1bd0
761 761
762 def subdiruipathfn(subpath, uipathfn): 762 def subdiruipathfn(subpath, uipathfn):
763 '''Create a new uipathfn that treats the file as relative to subpath.''' 763 '''Create a new uipathfn that treats the file as relative to subpath.'''
764 return lambda f: uipathfn(posixpath.join(subpath, f)) 764 return lambda f: uipathfn(posixpath.join(subpath, f))
765 765
766 def anypats(pats, opts):
767 '''Checks if any patterns, including --include and --exclude were given.
768
769 Some commands (e.g. addremove) use this condition for deciding whether to
770 print absolute or relative paths.
771 '''
772 return bool(pats or opts.get('include') or opts.get('exclude'))
773
766 def expandpats(pats): 774 def expandpats(pats):
767 '''Expand bare globs when running on windows. 775 '''Expand bare globs when running on windows.
768 On posix we assume it already has already been done by sh.''' 776 On posix we assume it already has already been done by sh.'''
769 if not util.expandglobs: 777 if not util.expandglobs:
770 return list(pats) 778 return list(pats)
1029 tostrip = list(n for ns in replacements for n in ns) 1037 tostrip = list(n for ns in replacements for n in ns)
1030 if tostrip: 1038 if tostrip:
1031 repair.delayedstrip(repo.ui, repo, tostrip, operation, 1039 repair.delayedstrip(repo.ui, repo, tostrip, operation,
1032 backup=backup) 1040 backup=backup)
1033 1041
1034 def addremove(repo, matcher, prefix, opts=None): 1042 def addremove(repo, matcher, prefix, uipathfn, opts=None):
1035 if opts is None: 1043 if opts is None:
1036 opts = {} 1044 opts = {}
1037 m = matcher 1045 m = matcher
1038 dry_run = opts.get('dry_run') 1046 dry_run = opts.get('dry_run')
1039 try: 1047 try:
1050 for subpath in sorted(wctx.substate): 1058 for subpath in sorted(wctx.substate):
1051 submatch = matchmod.subdirmatcher(subpath, m) 1059 submatch = matchmod.subdirmatcher(subpath, m)
1052 if opts.get('subrepos') or m.exact(subpath) or any(submatch.files()): 1060 if opts.get('subrepos') or m.exact(subpath) or any(submatch.files()):
1053 sub = wctx.sub(subpath) 1061 sub = wctx.sub(subpath)
1054 subprefix = repo.wvfs.reljoin(prefix, subpath) 1062 subprefix = repo.wvfs.reljoin(prefix, subpath)
1063 subuipathfn = subdiruipathfn(subpath, uipathfn)
1055 try: 1064 try:
1056 if sub.addremove(submatch, subprefix, opts): 1065 if sub.addremove(submatch, subprefix, subuipathfn, opts):
1057 ret = 1 1066 ret = 1
1058 except error.LookupError: 1067 except error.LookupError:
1059 repo.ui.status(_("skipping missing subrepository: %s\n") 1068 repo.ui.status(_("skipping missing subrepository: %s\n")
1060 % m.uipath(subpath)) 1069 % uipathfn(subpath))
1061 1070
1062 rejected = [] 1071 rejected = []
1063 def badfn(f, msg): 1072 def badfn(f, msg):
1064 if f in m.files(): 1073 if f in m.files():
1065 m.bad(f, msg) 1074 m.bad(f, msg)
1073 toprint = unknownset.copy() 1082 toprint = unknownset.copy()
1074 toprint.update(deleted) 1083 toprint.update(deleted)
1075 for abs in sorted(toprint): 1084 for abs in sorted(toprint):
1076 if repo.ui.verbose or not m.exact(abs): 1085 if repo.ui.verbose or not m.exact(abs):
1077 if abs in unknownset: 1086 if abs in unknownset:
1078 status = _('adding %s\n') % m.uipath(abs) 1087 status = _('adding %s\n') % uipathfn(abs)
1079 label = 'ui.addremove.added' 1088 label = 'ui.addremove.added'
1080 else: 1089 else:
1081 status = _('removing %s\n') % m.uipath(abs) 1090 status = _('removing %s\n') % uipathfn(abs)
1082 label = 'ui.addremove.removed' 1091 label = 'ui.addremove.removed'
1083 repo.ui.status(status, label=label) 1092 repo.ui.status(status, label=label)
1084 1093
1085 renames = _findrenames(repo, m, added + unknown, removed + deleted, 1094 renames = _findrenames(repo, m, added + unknown, removed + deleted,
1086 similarity) 1095 similarity)