本文整理汇总了Python中mercurial.encoding.fromlocal函数的典型用法代码示例。如果您正苦于以下问题:Python fromlocal函数的具体用法?Python fromlocal怎么用?Python fromlocal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fromlocal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: chash
def chash(manifest, files, desc, p1, p2, user, date, extra):
"""Compute changeset hash from the changeset pieces."""
user = user.strip()
if "\n" in user:
raise error.RevlogError(_("username %s contains a newline")
% repr(user))
# strip trailing whitespace and leading and trailing empty lines
desc = '\n'.join([l.rstrip() for l in desc.splitlines()]).strip('\n')
user, desc = encoding.fromlocal(user), encoding.fromlocal(desc)
if date:
parseddate = "%d %d" % util.parsedate(date)
else:
parseddate = "%d %d" % util.makedate()
extra = extra.copy()
if 'signature' in extra:
del extra['signature']
if extra.get("branch") in ("default", ""):
del extra["branch"]
if extra:
extra = changelog.encodeextra(extra)
parseddate = "%s %s" % (parseddate, extra)
l = [hex(manifest), user, parseddate] + sorted(files) + ["", desc]
text = "\n".join(l)
return revlog.hash(text, p1, p2)
示例2: _update_issue
def _update_issue(ui, repo, node, **kwargs):
"""Update a Roundup issue for corresponding changesets.
Return True if updating the Roundup issue fails, else False.
"""
repourl = ui.config('hgroundup', 'repourl')
if not repourl:
repourl = posixpath.join(ui.config('web', 'baseurl'), 'rev/')
fromaddr = ui.config('hgroundup', 'fromaddr')
toaddr = ui.config('hgroundup', 'toaddr')
for var in ('repourl', 'fromaddr', 'toaddr'):
if not locals()[var]:
raise RuntimeError(
'roundup hook not configured properly,\nplease '
'set the "%s" property in the [hgroundup] section'
% var)
start = repo[node].rev()
issues = {}
for rev in xrange(start, len(repo)):
ctx = repo[rev]
description = fromlocal(ctx.description().strip())
matches = ISSUE_PATTERN.finditer(description)
ids = set()
for match in matches:
data = match.groupdict()
ui.debug('match in commit msg: %s\n' % data)
# check for duplicated issue numbers in the same commit msg
if data['issue_id'] in ids:
continue
ids.add(data['issue_id'])
comment = Template(COMMENT_TEMPLATE).substitute({
'author': fromlocal(person(ctx.user())),
'branch': ctx.branch(),
'changeset_id': str(ctx),
'changeset_url': posixpath.join(repourl, str(ctx)),
'commit_msg': description.splitlines()[0],
})
add_comment(issues, data, comment)
if issues:
smtp_host = ui.config('smtp', 'host', default='localhost')
smtp_port = int(ui.config('smtp', 'port', 25))
s = smtplib.SMTP(smtp_host, smtp_port)
username = ui.config('smtp', 'username', '')
if username:
password = ui.config('smtp', 'password', '')
s.login(username, password)
try:
send_comments(s, fromaddr, toaddr, issues)
ui.status("sent email to roundup at " + toaddr + '\n')
except Exception, err:
# make sure an issue updating roundup does not prevent an
# otherwise successful push.
ui.warn("sending email to roundup at %s failed: %s\n" %
(toaddr, err))
示例3: write
def write(repo):
'''Write bookmarks
Write the given bookmark => hash dictionary to the .hg/bookmarks file
in a format equal to those of localtags.
We also store a backup of the previous state in undo.bookmarks that
can be copied back on rollback.
'''
refs = repo._bookmarks
if repo._bookmarkcurrent not in refs:
setcurrent(repo, None)
for mark in refs.keys():
if not valid(mark):
raise util.Abort(_("bookmark '%s' contains illegal "
"character" % mark))
wlock = repo.wlock()
try:
file = repo.opener('bookmarks', 'w', atomictemp=True)
for refspec, node in refs.iteritems():
file.write("%s %s\n" % (hex(node), encoding.fromlocal(refspec)))
file.close()
# touch 00changelog.i so hgweb reloads bookmarks (no lock needed)
try:
os.utime(repo.sjoin('00changelog.i'), None)
except OSError:
pass
finally:
wlock.release()
示例4: sendchanges
def sendchanges(ui, master, changes):
# send change information to one master
from buildbot.clients import sendchange
s = sendchange.Sender(master)
d = defer.Deferred()
reactor.callLater(0, d.callback, None)
def send(res, c):
return s.send(**c)
for change in changes:
for k, v in change.items():
# Yikes!
if isinstance(v, localstr):
change[k] = fromlocal(v).decode('utf8', 'replace')
elif isinstance(v, str):
change[k] = v.decode('utf8', 'replace')
d.addCallback(send, change)
def printSuccess(res):
print "change(s) sent successfully"
def printFailure(why):
print "change(s) NOT sent, something went wrong:"
print why
d.addCallbacks(printSuccess, printFailure)
d.addBoth(lambda _: reactor.stop())
示例5: write
def write(self):
'''Write bookmarks
Write the given bookmark => hash dictionary to the .hg/bookmarks file
in a format equal to those of localtags.
We also store a backup of the previous state in undo.bookmarks that
can be copied back on rollback.
'''
repo = self._repo
if repo._bookmarkcurrent not in self:
setcurrent(repo, None)
wlock = repo.wlock()
try:
file = repo.vfs('bookmarks', 'w', atomictemp=True)
for name, node in self.iteritems():
file.write("%s %s\n" % (hex(node), encoding.fromlocal(name)))
file.close()
# touch 00changelog.i so hgweb reloads bookmarks (no lock needed)
try:
repo.svfs.utime('00changelog.i', None)
except OSError:
pass
finally:
wlock.release()
示例6: expandpath
def expandpath(path, default=None):
ep = oldexpandpath(path, default)
if ep != path:
return ep
bent = store.encodefilename(encoding.fromlocal(path))
if os.path.isdir(os.path.join('.hg', 'branches', bent)):
return 'lbranch://%s' % path
return ep
示例7: loadlocalbranch
def loadlocalbranch(self, branch):
spath = self.localbranchpath(encoding.fromlocal(branch))
if spath != repo.spath:
if not os.path.isdir(spath):
raise util.Abort(_('local branch %s not found') % branch)
self.store = store.store(self.getrequirements(), spath, util.opener)
self.spath = self.store.path
self.sopener = self.store.opener
self.sopener.options = {}
示例8: _set_bookmark
def _set_bookmark(repo, mark):
"""Set the name of the remote branch that the repo is tracking."""
# Based on bookmarks.setcurrent
wlock = repo.wlock()
try:
file = repo.opener('bookrepos.bookmark', 'w', atomictemp=True)
file.write(encoding.fromlocal(mark))
file.close()
finally:
wlock.release()
示例9: localbranch
def localbranch(self, name):
# switch to local branch, creating if necessary
def checkdir(d):
if not os.path.isdir(d):
if os.path.exists(d):
raise util.Abort(_('%s is not a directory') % d)
return False
return True
if self.dirstate.parents()[1] != nullid:
raise util.Abort(_('merge in progress'))
obranch = self.getlocalbranch()
lname = encoding.fromlocal(name)
if obranch == name:
return
omf = self.changectx('').manifest()
del self.changelog
del self.manifest
if not name:
lbpath = self.join('localbranch')
if os.path.exists(lbpath):
os.unlink(lbpath)
else:
bdir = self.join('branches')
if not checkdir(bdir):
os.mkdir(bdir)
dest = os.path.join(bdir, store.encodefilename(lname))
if not checkdir(dest):
# check for non-store layout
if self.spath == self.path:
os.mkdir(dest)
datadir = os.path.join(dest, 'data')
util.copyfiles(self.join('data'), datadir)
for f in ('00changelog.i', '00changelog.d',
'00manifest.i', '00manifest.d'):
src = self.join(f)
if os.path.exists(src):
util.copyfiles(src, os.path.join(dest, f))
else:
os.mkdir(dest)
spath = os.path.join(dest, 'store')
util.copyfiles(self.spath, spath)
self.opener('localbranch', 'w').write(lname + '\n')
self.loadlocalbranch(name)
ctx = repo.changectx('tip')
wlock = self.wlock()
try:
self.refreshdirstate(ctx, omf)
finally:
wlock.release()
示例10: makememctx
def makememctx(repo, ctx, revmap, copyfilectxfn):
parents = newparents(repo, ctx, revmap)
# Need to make a copy otherwise modification is made on original,
# which is just plain wrong.
msg = encoding.fromlocal(ctx.description())
new_msg, changed = addcommitid(msg, repo=repo)
memctx = context.memctx(repo, parents,
encoding.tolocal(new_msg), ctx.files(),
copyfilectxfn, user=ctx.user(),
date=ctx.date(), extra=dict(ctx.extra()))
return memctx
示例11: write_tag
def write_tag(self, ref):
node = self.parsed_refs[ref]
tag = git_to_hg_spaces(ref[len('refs/tags/'):])
branch = self.repo[node].branch()
# Calling self.repo.tag() doesn't append the tag to the correct
# commit. So I copied some of localrepo._tag into here.
# But that method, like much of mercurial's code, is ugly.
# So I then rewrote it.
tags_revision = revsingle(self.repo, hghex(branch_tip(self.repo, branch)))
if '.hgtags' in tags_revision:
old_tags = tags_revision['.hgtags'].data()
else:
old_tags = ''
newtags = [old_tags]
if old_tags and old_tags[-1] != '\n':
newtags.append('\n')
encoded_tag = encoding.fromlocal(tag)
tag_line = '%s %s' % (hghex(node), encoded_tag)
if tag_line in old_tags:
return # Don't commit a tag that was previously committed
newtags.append(tag_line)
def get_filectx(repo, memctx, file):
return memfilectx(file, ''.join(newtags))
if tag in self.parsed_tags:
author, message = self.parsed_tags[tag]
user, date, tz = author
date_tz = (date, tz)
else:
message = "Added tag %s for changeset %s" % (tag, hgshort(node))
user = None
date_tz = None
ctx = memctx(self.repo,
(branch_tip(self.repo, branch), self.NULL_PARENT), message,
['.hgtags'], get_filectx, user, date_tz, {'branch': branch})
tmp = encoding.encoding
encoding.encoding = 'utf-8'
node = self.repo.commitctx(ctx)
encoding.encoding = tmp
示例12: alignString
def alignString(self, inStr, window):
"""
Add whitespace to the end of a string in order to make it fill
the screen in the x direction. The current cursor position is
taken into account when making this calculation. The string can span
multiple lines.
"""
y,xStart = window.getyx()
width = self.xScreenSize
# turn tabs into spaces
inStr = inStr.expandtabs(4)
try:
strLen = len(unicode(encoding.fromlocal(inStr), code))
except:
# if text is not utf8, then assume an 8-bit single-byte encoding.
strLen = len(inStr)
numSpaces = (width - ((strLen + xStart) % width) - 1)
return inStr + " " * numSpaces + "\n"
示例13: activate
def activate(repo, mark):
"""
Set the given bookmark to be 'active', meaning that this bookmark will
follow new commits that are made.
The name is recorded in .hg/bookmarks.current
"""
if mark not in repo._bookmarks:
raise AssertionError('bookmark %s does not exist!' % mark)
active = repo._activebookmark
if active == mark:
return
wlock = repo.wlock()
try:
file = repo.vfs('bookmarks.current', 'w', atomictemp=True)
file.write(encoding.fromlocal(mark))
file.close()
finally:
wlock.release()
repo._activebookmark = mark
示例14: setcurrent
def setcurrent(repo, mark):
'''Set the name of the bookmark that we are currently on
Set the name of the bookmark that we are on (hg update <bookmark>).
The name is recorded in .hg/bookmarks.current
'''
if mark not in repo._bookmarks:
raise AssertionError('bookmark %s does not exist!' % mark)
current = repo._bookmarkcurrent
if current == mark:
return
wlock = repo.wlock()
try:
file = repo.vfs('bookmarks.current', 'w', atomictemp=True)
file.write(encoding.fromlocal(mark))
file.close()
finally:
wlock.release()
repo._bookmarkcurrent = mark
示例15: setcurrent
def setcurrent(repo, mark):
'''Set the name of the bookmark that we are currently on
Set the name of the bookmark that we are on (hg update <bookmark>).
The name is recorded in .hg/bookmarks.current
'''
current = repo._bookmarkcurrent
if current == mark:
return
if mark not in repo._bookmarks:
mark = ''
wlock = repo.wlock()
try:
file = repo.opener('bookmarks.current', 'w', atomictemp=True)
file.write(encoding.fromlocal(mark))
file.close()
finally:
wlock.release()
repo._bookmarkcurrent = mark