def checkstatus(repo, subset, pat, field): m = None s = [] fast = not matchmod.patkind(pat) for r in subset: c = repo[r] if fast: if pat not in c.files(): continue else: if not m or matchmod.patkind(pat) == 'set': m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c) for f in c.files(): if m(f): break else: continue files = repo.status(c.p1().node(), c.node())[field] if fast: if pat in files: s.append(r) else: for f in files: if m(f): s.append(r) break return s
def filelog(repo, subset, x): """``filelog(pattern)`` Changesets connected to the specified filelog. """ pat = getstring(x, _("filelog requires a pattern")) m = matchmod.match(repo.root, repo.getcwd(), [pat], default='relpath', ctx=repo[None]) s = set() if not matchmod.patkind(pat): for f in m.files(): fl = repo.file(f) for fr in fl: s.add(fl.linkrev(fr)) else: for f in repo[None]: if m(f): fl = repo.file(f) for fr in fl: s.add(fl.linkrev(fr)) return [r for r in subset if r in s]
def checkstatus(repo, subset, pat, field): m = None s = [] hasset = matchmod.patkind(pat) == 'set' fname = None for r in subset: c = repo[r] if not m or hasset: m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c) if not m.anypats() and len(m.files()) == 1: fname = m.files()[0] if fname is not None: if fname not in c.files(): continue else: for f in c.files(): if m(f): break else: continue files = repo.status(c.p1().node(), c.node())[field] if fname is not None: if fname in files: s.append(r) else: for f in files: if m(f): s.append(r) break return s
def _matchfiles(repo, subset, x): # _matchfiles takes a revset list of prefixed arguments: # # [p:foo, i:bar, x:baz] # # builds a match object from them and filters subset. Allowed # prefixes are 'p:' for regular patterns, 'i:' for include # patterns and 'x:' for exclude patterns. Use 'r:' prefix to pass # a revision identifier, or the empty string to reference the # working directory, from which the match object is # initialized. Use 'd:' to set the default matching mode, default # to 'glob'. At most one 'r:' and 'd:' argument can be passed. # i18n: "_matchfiles" is a keyword l = getargs(x, 1, -1, _("_matchfiles requires at least one argument")) pats, inc, exc = [], [], [] hasset = False rev, default = None, None for arg in l: s = getstring(arg, _("_matchfiles requires string arguments")) prefix, value = s[:2], s[2:] if prefix == 'p:': pats.append(value) elif prefix == 'i:': inc.append(value) elif prefix == 'x:': exc.append(value) elif prefix == 'r:': if rev is not None: raise error.ParseError(_('_matchfiles expected at most one ' 'revision')) rev = value elif prefix == 'd:': if default is not None: raise error.ParseError(_('_matchfiles expected at most one ' 'default mode')) default = value else: raise error.ParseError(_('invalid _matchfiles prefix: %s') % prefix) if not hasset and matchmod.patkind(value) == 'set': hasset = True if not default: default = 'glob' m = None s = [] for r in subset: c = repo[r] if not m or (hasset and rev is None): ctx = c if rev is not None: ctx = repo[rev or None] m = matchmod.match(repo.root, repo.getcwd(), pats, include=inc, exclude=exc, ctx=ctx, default=default) for f in c.files(): if m(f): s.append(r) break return s
def contains(repo, subset, x): """``contains(pattern)`` Revision contains a file matching pattern. See :hg:`help patterns` for information about file patterns. """ # i18n: "contains" is a keyword pat = getstring(x, _("contains requires a pattern")) m = None s = [] if not matchmod.patkind(pat): for r in subset: if pat in repo[r]: s.append(r) else: for r in subset: c = repo[r] if not m or matchmod.patkind(pat) == 'set': m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c) for f in c.manifest(): if m(f): s.append(r) break return s
def hasfile(repo, subset, x): """``file(pattern)`` Changesets affecting files matched by pattern. """ # i18n: "file" is a keyword pat = getstring(x, _("file requires a pattern")) m = None s = [] for r in subset: c = repo[r] if not m or matchmod.patkind(pat) == 'set': m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c) for f in c.files(): if m(f): s.append(r) break return s
def subrepo(mctx, x): """``subrepo([pattern])`` Subrepositories whose paths match the given pattern. """ # i18n: "subrepo" is a keyword getargs(x, 0, 1, _("subrepo takes at most one argument")) ctx = mctx.ctx sstate = sorted(ctx.substate) if x: pat = getstring(x, _("subrepo requires a pattern or no arguments")) import match as matchmod # avoid circular import issues fast = not matchmod.patkind(pat) if fast: def m(s): return (s == pat) else: m = matchmod.match(ctx._repo.root, '', [pat], ctx=ctx) return [sub for sub in sstate if m(sub)] else: return [sub for sub in sstate]
def targetpathafterfn(pat, dest, srcs): if _match.patkind(pat): # a mercurial pattern res = lambda p: os.path.join(dest, os.path.basename(util.localpath(p))) else: abspfx = util.canonpath(repo.root, cwd, pat) if len(abspfx) < len(srcs[0][0]): # A directory. Either the target path contains the last # component of the source path or it does not. def evalpath(striplen): score = 0 for s in srcs: t = os.path.join(dest, util.localpath(s[0])[striplen:]) if os.path.exists(t): score += 1 return score abspfx = util.localpath(abspfx) striplen = len(abspfx) if striplen: striplen += len(os.sep) if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): score = evalpath(striplen) striplen1 = len(os.path.split(abspfx)[0]) if striplen1: striplen1 += len(os.sep) if evalpath(striplen1) > score: striplen = striplen1 res = lambda p: os.path.join(dest, util.localpath(p)[striplen:]) else: # a file if destdirexists: res = lambda p: os.path.join( dest, os.path.basename(util.localpath(p))) else: res = lambda p: dest return res
def targetpathafterfn(pat, dest, srcs): if matchmod.patkind(pat): # a mercurial pattern res = lambda p: os.path.join(dest, os.path.basename(util.localpath(p))) else: abspfx = util.canonpath(repo.root, cwd, pat) if len(abspfx) < len(srcs[0][0]): # A directory. Either the target path contains the last # component of the source path or it does not. def evalpath(striplen): score = 0 for s in srcs: t = os.path.join(dest, util.localpath(s[0])[striplen:]) if os.path.lexists(t): score += 1 return score abspfx = util.localpath(abspfx) striplen = len(abspfx) if striplen: striplen += len(os.sep) if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): score = evalpath(striplen) striplen1 = len(os.path.split(abspfx)[0]) if striplen1: striplen1 += len(os.sep) if evalpath(striplen1) > score: striplen = striplen1 res = lambda p: os.path.join(dest, util.localpath(p)[striplen:]) else: # a file if destdirexists: res = lambda p: os.path.join(dest, os.path.basename(util.localpath(p))) else: res = lambda p: dest return res
res = lambda p: os.path.join(dest, os.path.basename(util.localpath(p))) else: res = lambda p: dest return res pats = expandpats(pats) if not pats: raise util.Abort(_('no source or destination specified')) if len(pats) == 1: raise util.Abort(_('no destination specified')) dest = pats.pop() destdirexists = os.path.isdir(dest) and not os.path.islink(dest) if not destdirexists: if len(pats) > 1 or matchmod.patkind(pats[0]): raise util.Abort(_('with multiple sources, destination must be an ' 'existing directory')) if util.endswithsep(dest): raise util.Abort(_('destination %s is not a directory') % dest) tfn = targetpathfn if after: tfn = targetpathafterfn copylist = [] for pat in pats: srcs = walkpat(pat) if not srcs: continue copylist.append((tfn(pat, dest, srcs), srcs)) if not copylist:
def _matchfiles(repo, subset, x): # _matchfiles takes a revset list of prefixed arguments: # # [p:foo, i:bar, x:baz] # # builds a match object from them and filters subset. Allowed # prefixes are 'p:' for regular patterns, 'i:' for include # patterns and 'x:' for exclude patterns. Use 'r:' prefix to pass # a revision identifier, or the empty string to reference the # working directory, from which the match object is # initialized. Use 'd:' to set the default matching mode, default # to 'glob'. At most one 'r:' and 'd:' argument can be passed. # i18n: "_matchfiles" is a keyword l = getargs(x, 1, -1, _("_matchfiles requires at least one argument")) pats, inc, exc = [], [], [] hasset = False rev, default = None, None for arg in l: s = getstring(arg, _("_matchfiles requires string arguments")) prefix, value = s[:2], s[2:] if prefix == 'p:': pats.append(value) elif prefix == 'i:': inc.append(value) elif prefix == 'x:': exc.append(value) elif prefix == 'r:': if rev is not None: raise error.ParseError( _('_matchfiles expected at most one ' 'revision')) rev = value elif prefix == 'd:': if default is not None: raise error.ParseError( _('_matchfiles expected at most one ' 'default mode')) default = value else: raise error.ParseError( _('invalid _matchfiles prefix: %s') % prefix) if not hasset and matchmod.patkind(value) == 'set': hasset = True if not default: default = 'glob' m = None s = [] for r in subset: c = repo[r] if not m or (hasset and rev is None): ctx = c if rev is not None: ctx = repo[rev or None] m = matchmod.match(repo.root, repo.getcwd(), pats, include=inc, exclude=exc, ctx=ctx, default=default) for f in c.files(): if m(f): s.append(r) break return s
res = lambda p: os.path.join(dest, os.path.basename(util.localpath(p))) else: res = lambda p: dest return res pats = expandpats(pats) if not pats: raise util.Abort(_('no source or destination specified')) if len(pats) == 1: raise util.Abort(_('no destination specified')) dest = pats.pop() destdirexists = os.path.isdir(dest) and not os.path.islink(dest) if not destdirexists: if len(pats) > 1 or _match.patkind(pats[0]): raise util.Abort(_('with multiple sources, destination must be an ' 'existing directory')) if util.endswithsep(dest): raise util.Abort(_('destination %s is not a directory') % dest) tfn = targetpathfn if after: tfn = targetpathafterfn copylist = [] for pat in pats: srcs = walkpat(pat) if not srcs: continue copylist.append((tfn(pat, dest, srcs), srcs)) if not copylist:
if destdirexists: res = lambda p: os.path.join( dest, os.path.basename(util.localpath(p))) else: res = lambda p: dest return res pats = expandpats(pats) if not pats: raise util.Abort(_('no source or destination specified')) if len(pats) == 1: raise util.Abort(_('no destination specified')) dest = pats.pop() destdirexists = os.path.isdir(dest) and not os.path.islink(dest) if not destdirexists: if len(pats) > 1 or _match.patkind(pats[0]): raise util.Abort( _('with multiple sources, destination must be an ' 'existing directory')) if util.endswithsep(dest): raise util.Abort(_('destination %s is not a directory') % dest) tfn = targetpathfn if after: tfn = targetpathafterfn copylist = [] for pat in pats: srcs = walkpat(pat) if not srcs: continue copylist.append((tfn(pat, dest, srcs), srcs))
if destdirexists: res = lambda p: os.path.join( dest, os.path.basename(util.localpath(p))) else: res = lambda p: dest return res pats = scmutil.expandpats(pats) if not pats: raise util.Abort(_('no source or destination specified')) if len(pats) == 1: raise util.Abort(_('no destination specified')) dest = pats.pop() destdirexists = os.path.isdir(dest) and not os.path.islink(dest) if not destdirexists: if len(pats) > 1 or matchmod.patkind(pats[0]): raise util.Abort( _('with multiple sources, destination must be an ' 'existing directory')) if util.endswithsep(dest): raise util.Abort(_('destination %s is not a directory') % dest) tfn = targetpathfn if after: tfn = targetpathafterfn copylist = [] for pat in pats: srcs = walkpat(pat) if not srcs: continue copylist.append((tfn(pat, dest, srcs), srcs))