本文整理汇总了Python中mercurial.match.exact函数的典型用法代码示例。如果您正苦于以下问题:Python exact函数的具体用法?Python exact怎么用?Python exact使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了exact函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: commit_multi
def commit_multi(proj, asset, filenames, text, username=None):
"""Commit multiple files to the repository and returns the revision id."""
repo_path = os.path.join(G.REPOSITORY, proj)
repo = repo_get(proj)
if not isinstance(filenames, list):
raise SPAMRepoError('expected a list of files for asset %s' % asset.id)
text = 'asset %s - %s' % (asset.id, text)
encodedtext = text.encode('utf-8')
target_sequence_path = asset.path.replace('#', '%04d')
targets = []
for i, filename in enumerate(filenames):
n = i + 1
uploadedfile = os.path.join(G.UPLOAD, filename)
target_path = (target_sequence_path % n).encode()
target_repo_path = os.path.join(repo_path, target_path)
if not os.path.exists(os.path.dirname(target_repo_path)):
os.makedirs(os.path.dirname(target_repo_path))
shutil.move(uploadedfile, target_repo_path)
if not target_path in repo['tip']:
commands.add(repo_ui, repo, target_repo_path)
targets.append(target_path)
matched = match.exact(repo.root, repo.getcwd(), targets)
commit_id = repo.commit(encodedtext, user=username, match=matched)
if commit_id:
return repo[commit_id].hex()
else:
return None
示例2: get_paths
def get_paths():
matcher = match.exact(self.repository.basedir,
self.repository.basedir,
[subdir])
walk = self._getRepo().dirstate.walk
for path in walk(matcher, True, False):
yield path
示例3: diffs
def diffs(repo, tmpl, ctx, basectx, files, parity, style):
def countgen():
start = 1
while True:
yield start
start += 1
blockcount = countgen()
def prettyprintlines(diff, blockno):
for lineno, l in enumerate(diff.splitlines(True)):
difflineno = "%d.%d" % (blockno, lineno + 1)
if l.startswith('+'):
ltype = "difflineplus"
elif l.startswith('-'):
ltype = "difflineminus"
elif l.startswith('@'):
ltype = "difflineat"
else:
ltype = "diffline"
yield tmpl(ltype,
line=l,
lineno=lineno + 1,
lineid="l%s" % difflineno,
linenumber="% 8s" % difflineno)
if files:
m = match.exact(repo.root, repo.getcwd(), files)
else:
m = match.always(repo.root, repo.getcwd())
diffopts = patch.diffopts(repo.ui, untrusted=True)
if basectx is None:
parents = ctx.parents()
if parents:
node1 = parents[0].node()
else:
node1 = nullid
else:
node1 = basectx.node()
node2 = ctx.node()
block = []
for chunk in patch.diff(repo, node1, node2, m, opts=diffopts):
if chunk.startswith('diff') and block:
blockno = blockcount.next()
yield tmpl('diffblock', parity=parity.next(), blockno=blockno,
lines=prettyprintlines(''.join(block), blockno))
block = []
if chunk.startswith('diff') and style != 'raw':
chunk = ''.join(chunk.splitlines(True)[1:])
block.append(chunk)
blockno = blockcount.next()
yield tmpl('diffblock', parity=parity.next(), blockno=blockno,
lines=prettyprintlines(''.join(block), blockno))
示例4: getstatus
def getstatus(repo, n1, n2, wfile):
m = match.exact(repo.root, repo.getcwd(), [wfile])
modified, added, removed = repo.status(n1, n2, match=m)[:3]
if wfile in modified:
return 'M'
if wfile in added:
return 'A'
if wfile in removed:
return 'R'
if wfile in ctx:
return 'C'
return None
示例5: applyone
def applyone(self, repo, node, cl, patchfile, merge=False, log=False,
filter=None):
'''apply the patch in patchfile to the repository as a transplant'''
(manifest, user, (time, timezone), files, message) = cl[:5]
date = "%d %d" % (time, timezone)
extra = {'transplant_source': node}
if filter:
(user, date, message) = self.filter(filter, node, cl, patchfile)
if log:
# we don't translate messages inserted into commits
message += '\n(transplanted from %s)' % nodemod.hex(node)
self.ui.status(_('applying %s\n') % nodemod.short(node))
self.ui.note('%s %s\n%s\n' % (user, date, message))
if not patchfile and not merge:
raise error.Abort(_('can only omit patchfile if merging'))
if patchfile:
try:
files = set()
patch.patch(self.ui, repo, patchfile, files=files, eolmode=None)
files = list(files)
except Exception as inst:
seriespath = os.path.join(self.path, 'series')
if os.path.exists(seriespath):
os.unlink(seriespath)
p1 = repo.dirstate.p1()
p2 = node
self.log(user, date, message, p1, p2, merge=merge)
self.ui.write(str(inst) + '\n')
raise TransplantError(_('fix up the working directory and run '
'hg transplant --continue'))
else:
files = None
if merge:
p1, p2 = repo.dirstate.parents()
repo.setparents(p1, node)
m = match.always(repo.root, '')
else:
m = match.exact(repo.root, '', files)
n = repo.commit(message, user, date, extra=extra, match=m,
editor=self.getcommiteditor())
if not n:
self.ui.warn(_('skipping emptied changeset %s\n') %
nodemod.short(node))
return None
if not merge:
self.transplants.set(n, node)
return n
示例6: _makematcher
def _makematcher(repo, ctx, pat, changedonly):
cwd = '' # always relative to repo root
patterns = []
if pat and ':' not in pat and '*' not in pat:
# mimic case-insensitive partial string match
patterns.append('relre:(?i)' + re.escape(pat))
elif pat:
patterns.append(pat)
include = []
if changedonly:
include.extend('path:%s' % p for p in ctx.files())
if not include:
# no match
return matchmod.exact(repo.root, cwd, [])
try:
return matchmod.match(repo.root, cwd, patterns, include=include,
default='relglob', auditor=repo.auditor, ctx=ctx)
except (error.Abort, error.ParseError):
# no match
return matchmod.exact(repo.root, cwd, [])
示例7: buildmatch
def buildmatch(ui, repo, user, key):
'''return tuple of (match function, list enabled).'''
if not ui.has_section(key):
ui.debug(_('acl: %s not enabled\n') % key)
return None
pats = [pat for pat, users in ui.configitems(key)
if user in users.replace(',', ' ').split()]
ui.debug(_('acl: %s enabled, %d entries for user %s\n') %
(key, len(pats), user))
if pats:
return match.match(repo.root, '', pats)
return match.exact(repo.root, '', [])
示例8: _checkRenamed
def _checkRenamed(self, repo, ctx, pctx, wfile):
m = match.exact(repo, '', [wfile])
copy = copies.pathcopies(pctx, ctx, match=m)
oldname = copy.get(wfile)
if not oldname:
self.flabel += _(' <i>(was added)</i>')
return
fr = hglib.tounicode(oldname)
if oldname in ctx:
self.flabel += _(' <i>(copied from %s)</i>') % fr
else:
self.flabel += _(' <i>(renamed from %s)</i>') % fr
return oldname
示例9: buildmatch
def buildmatch(ui, repo, user, key):
'''return tuple of (match function, list enabled).'''
if not ui.has_section(key):
ui.debug('acl: %s not enabled\n' % key)
return None
pats = [pat for pat, users in ui.configitems(key)
if _usermatch(ui, user, users)]
ui.debug('acl: %s enabled, %d entries for user %s\n' %
(key, len(pats), user))
if not repo:
if pats:
return lambda b: '*' in pats or b in pats
return lambda b: False
if pats:
return match.match(repo.root, '', pats)
return match.exact(repo.root, '', [])
示例10: diffs
def diffs(repo, tmpl, ctx, files, parity, style):
def countgen():
start = 1
while True:
yield start
start += 1
blockcount = countgen()
def prettyprintlines(diff):
blockno = blockcount.next()
for lineno, l in enumerate(diff.splitlines(True)):
lineno = "%d.%d" % (blockno, lineno + 1)
if l.startswith("+"):
ltype = "difflineplus"
elif l.startswith("-"):
ltype = "difflineminus"
elif l.startswith("@"):
ltype = "difflineat"
else:
ltype = "diffline"
yield tmpl(ltype, line=l, lineid="l%s" % lineno, linenumber="% 8s" % lineno)
if files:
m = match.exact(repo.root, repo.getcwd(), files)
else:
m = match.always(repo.root, repo.getcwd())
diffopts = patch.diffopts(repo.ui, untrusted=True)
parents = ctx.parents()
node1 = parents and parents[0].node() or nullid
node2 = ctx.node()
block = []
for chunk in patch.diff(repo, node1, node2, m, opts=diffopts):
if chunk.startswith("diff") and block:
yield tmpl("diffblock", parity=parity.next(), lines=prettyprintlines("".join(block)))
block = []
if chunk.startswith("diff") and style != "raw":
chunk = "".join(chunk.splitlines(True)[1:])
block.append(chunk)
yield tmpl("diffblock", parity=parity.next(), lines=prettyprintlines("".join(block)))
示例11: repo_init
def repo_init(proj):
"""Init a new mercurial repository for ``proj``."""
repo_path = os.path.join(G.REPOSITORY, proj)
try:
repo = repo_get(proj)
except SPAMRepoNotFound:
commands.init(repo_ui, repo_path)
repo = repo_get(proj)
hgignore_path = os.path.join(G.REPOSITORY, proj, '.hgignore')
if not os.path.exists(hgignore_path):
hgignore = open(hgignore_path, 'w')
hgignore.write('syntax: regexp\n')
hgignore.write('^.previews/')
hgignore.close()
if not '.hgignore' in repo['tip']:
commands.add(repo_ui, repo, hgignore_path)
matched = match.exact(repo.root, repo.getcwd(), ['.hgignore'])
commit_id = repo.commit('add .hgignore', user='system', match=matched)
示例12: getChunksForFile
def getChunksForFile(self, wfile):
repo = self.repo
ctx = self.ctx
if isinstance(ctx, patchctx):
if wfile in ctx._files:
return ctx._files[wfile]
else:
return []
else:
buf = cStringIO.StringIO()
diffopts = patch.diffopts(repo.ui, {'git':True})
m = matchmod.exact(repo.root, repo.root, [wfile])
for p in patch.diff(repo, ctx.p1().node(), None, match=m,
opts=diffopts):
buf.write(p)
buf.seek(0)
chunks = record.parsepatch(buf)
if chunks:
header = chunks[0]
return [header] + header.hunks
else:
return []
示例13: versions
def versions(self, item):
local_repo = self._local_repo
instance_match = match.exact(local_repo.root, local_repo.getcwd(), [item])
change_contexts = walkchangerevs(local_repo, instance_match, {'rev': None}, lambda ctx, fns: ctx)
for change_context in change_contexts:
yield Version(change_context)
示例14: sign
def sign(ui, repo, *revs, **opts):
"""add a signature for the current or given revision
If no revision is given, the parent of the working directory is used,
or tip if no revision is checked out.
See :hg:`help dates` for a list of formats valid for -d/--date.
"""
mygpg = newgpg(ui, **opts)
sigver = "0"
sigmessage = ""
date = opts.get("date")
if date:
opts["date"] = util.parsedate(date)
if revs:
nodes = [repo.lookup(n) for n in revs]
else:
nodes = [node for node in repo.dirstate.parents() if node != hgnode.nullid]
if len(nodes) > 1:
raise util.Abort(_("uncommitted merge - please provide a " "specific revision"))
if not nodes:
nodes = [repo.changelog.tip()]
for n in nodes:
hexnode = hgnode.hex(n)
ui.write(_("signing %d:%s\n") % (repo.changelog.rev(n), hgnode.short(n)))
# build data
data = node2txt(repo, n, sigver)
sig = mygpg.sign(data)
if not sig:
raise util.Abort(_("error while signing"))
sig = binascii.b2a_base64(sig)
sig = sig.replace("\n", "")
sigmessage += "%s %s %s\n" % (hexnode, sigver, sig)
# write it
if opts["local"]:
repo.vfs.append("localsigs", sigmessage)
return
if not opts["force"]:
msigs = match.exact(repo.root, "", [".hgsigs"])
if util.any(repo.status(match=msigs, unknown=True, ignored=True)):
raise util.Abort(_("working copy of .hgsigs is changed "), hint=_("please commit .hgsigs manually"))
sigsfile = repo.wfile(".hgsigs", "ab")
sigsfile.write(sigmessage)
sigsfile.close()
if ".hgsigs" not in repo.dirstate:
repo[None].add([".hgsigs"])
if opts["no_commit"]:
return
message = opts["message"]
if not message:
# we don't translate commit messages
message = "\n".join(["Added signature for changeset %s" % hgnode.short(n) for n in nodes])
try:
editor = cmdutil.getcommiteditor(editform="gpg.sign", **opts)
repo.commit(message, opts["user"], opts["date"], match=msigs, editor=editor)
except ValueError, inst:
raise util.Abort(str(inst))
示例15: TransplantError
seriespath = os.path.join(self.path, "series")
if os.path.exists(seriespath):
os.unlink(seriespath)
p1 = repo.dirstate.p1()
p2 = node
self.log(user, date, message, p1, p2, merge=merge)
self.ui.write(str(inst) + "\n")
raise TransplantError(_("fix up the merge and run " "hg transplant --continue"))
else:
files = None
if merge:
p1, p2 = repo.dirstate.parents()
repo.setparents(p1, node)
m = match.always(repo.root, "")
else:
m = match.exact(repo.root, "", files)
n = repo.commit(message, user, date, extra=extra, match=m, editor=self.editor)
if not n:
self.ui.warn(_("skipping emptied changeset %s\n") % short(node))
return None
if not merge:
self.transplants.set(n, node)
return n
def resume(self, repo, source, opts):
"""recover last transaction and apply remaining changesets"""
if os.path.exists(os.path.join(self.path, "journal")):
n, node = self.recover(repo, source, opts)
self.ui.status(_("%s transplanted as %s\n") % (short(node), short(n)))