Commit ad143f80 authored by Steve Borho's avatar Steve Borho
Browse files

hgqt: branch, tag, bookmark APIs are all in local encoding

Reviewed all code under hgqt and verified all uses of UTF-8 are now valid.
parent b77c00662719
......@@ -142,8 +142,8 @@ class BookmarkDialog(QDialog):
def toggle_new_bookmark(self):
bookmark = self.bookmark_combo.currentText()
bookmarkutf = unicode(bookmark).encode('utf-8')
is_new = bookmarkutf not in self.repo.bookmarks
bookmarklocal = hglib.fromunicode(bookmark)
is_new = bookmarklocal not in self.repo.bookmarks
self.add_btn.setVisible(is_new)
self.add_btn.setDisabled(not is_new)
self.remove_btn.setVisible(not is_new)
......@@ -161,7 +161,7 @@ class BookmarkDialog(QDialog):
try:
# check if valid revision, tag, or branch
self.repo[unicode(revstr, 'utf-8')]
self.repo[hglib.fromunicode(revstr)]
except (error.LookupError, error.RepoLookupError, error.RepoError):
self.add_btn.setDisabled(True)
self.remove_btn.setDisabled(True)
......@@ -179,8 +179,8 @@ class BookmarkDialog(QDialog):
def add_bookmark(self):
bookmark = self.bookmark_combo.currentText()
bookmarkutf = unicode(bookmark).encode('utf-8')
if bookmarkutf in self.repo.bookmarks:
bookmarklocal = hglib.fromunicode(bookmark)
if bookmarklocal in self.repo.bookmarks:
self.set_status(_('A bookmark named "%s" already exists') %
bookmark, False)
return
......@@ -188,7 +188,7 @@ class BookmarkDialog(QDialog):
bookmarks.bookmark(ui=self.repo.ui,
repo=self.repo,
rev=self.initial_rev,
mark=bookmarkutf)
mark=bookmarklocal)
self.bookmark_combo.addItem(bookmark)
self.set_status(_("Bookmark '%s' has been added") % bookmark, True)
......@@ -197,14 +197,14 @@ class BookmarkDialog(QDialog):
def remove_bookmark(self):
bookmark = self.bookmark_combo.currentText()
bookmarkutf = unicode(bookmark).encode('utf-8')
if not bookmarkutf in self.repo.bookmarks:
bookmarklocal = hglib.fromunicode(bookmark)
if not bookmarklocal in self.repo.bookmarks:
self.set_status(_("Bookmark '%s' does not exist") % bookmark, False)
return
bookmarks.bookmark(ui=self.repo.ui,
repo=self.repo,
mark=bookmarkutf,
mark=bookmarklocal,
delete=True)
self.bookmark_combo.removeItem(self.bookmark_combo.currentIndex())
......@@ -214,23 +214,23 @@ class BookmarkDialog(QDialog):
def rename_bookmark(self):
name = self.bookmark_combo.currentText()
nameutf = unicode(name).encode('utf-8')
bookmarklocal = hglib.fromunicode(bookmark)
newname = self.new_name_text.text()
newnameutf = unicode(newname).encode('utf-8')
if not nameutf in self.repo.bookmarks:
newnamelocal = hglib.fromunicode(newname)
if not bookmarklocal in self.repo.bookmarks:
self.set_status(_("Bookmark '%s' does not exist") % name, False)
return
if newnameutf in self.repo.bookmarks:
if newnamelocal in self.repo.bookmarks:
self.set_status(_('A bookmark named "%s" already exists') %
newname, False)
return
bookmarks.bookmark(ui=self.repo.ui,
repo=self.repo,
mark=newnameutf,
rename=nameutf)
mark=newnamelocal,
rename=namelocal)
self.bookmark_combo.removeItem(self.bookmark_combo.currentIndex())
self.bookmark_combo.addItem(newname)
......
......@@ -249,7 +249,7 @@ class CommitWidget(QWidget):
self.msgcombo.reset(self.msghistory)
# Update branch operation button
branchu = unicode(self.repo[None].branch(), 'utf-8')
branchu = hglib.tounicode(self.repo[None].branch())
if self.branchop is None:
title = _('Branch: ') + branchu
elif self.branchop == False:
......@@ -520,15 +520,13 @@ class CommitWidget(QWidget):
brcmd = ['--close-branch']
else:
brcmd = []
# self.branchop - new branch name in QString (unicode)
# branchutf - new branch name in UTF8
branchutf = unicode(self.branchop).encode('utf-8')
if branchutf in repo.branchtags():
branch = hglib.fromunicode(self.branchop)
if branch in repo.branchtags():
# response: 0=Yes, 1=No, 2=Cancel
if branchutf in [p.branch() for p in repo.parents()]:
if branch in [p.branch() for p in repo.parents()]:
resp = 0
else:
rev = repo[branchutf].rev()
rev = repo[branch].rev()
resp = qtlib.CustomPrompt(_('Confirm Branch Change'),
_('Named branch "%s" already exists, '
'last used in revision %d\n'
......@@ -544,7 +542,7 @@ class CommitWidget(QWidget):
'Cancel\t- Cancel this commit') % self.branchop,
self, (_('&Yes'), _('&No'), _('Cancel')), 2, 2).run()
if resp == 0:
repo.dirstate.setbranch(branchutf)
repo.dirstate.setbranch(branch)
elif resp == 2:
return
files = self.stwidget.getChecked('MAR?!S')
......
......@@ -53,9 +53,9 @@ class RenameDialog(QDialog):
os.chdir(self.root)
fname = util.normpath(fname)
if target:
target = hglib.toutf(util.normpath(target))
target = hglib.tounicode(util.normpath(target))
else:
target = hglib.toutf(fname)
target = hglib.tounicode(fname)
return (fname, target)
def init_view(self, src, dest):
......
......@@ -463,13 +463,13 @@ class HgRepoListModel(QAbstractTableModel):
self.layoutChanged.emit()
def getbranch(self, ctx, gnode):
return unicode(ctx.branch(), 'utf-8')
return hglib.tounicode(ctx.branch())
def gettags(self, ctx, gnode):
if ctx.rev() is None:
return ''
tags = [t for t in ctx.tags() if t not in self._mqtags]
return unicode(','.join(tags), 'utf-8')
return hglib.tounicode(','.join(tags))
def getauthor(self, ctx, gnode):
try:
......@@ -492,7 +492,7 @@ class HgRepoListModel(QAbstractTableModel):
parts = []
if ctx.thgbranchhead():
branchu = unicode(ctx.branch(), 'utf-8')
branchu = hglib.tounicode(ctx.branch())
effects = qtlib.geteffect('log.branch')
parts.append(qtlib.applyeffects(u' %s ' % branchu, effects))
......@@ -509,8 +509,7 @@ class HgRepoListModel(QAbstractTableModel):
style = 'log.bookmark'
else:
style = 'log.tag'
# tag is in UTF-8, we need it in unicode with style effects
tagu = unicode(tag, 'utf-8')
tagu = hglib.tounicode(tag)
effects = qtlib.geteffect(style)
parts.append(qtlib.applyeffects(u' %s ' % tagu, effects))
......
......@@ -859,7 +859,7 @@ def version(ui, **opts):
"""output version and copyright information"""
ui.write(_('TortoiseHg Dialogs (version %s), '
'Mercurial (version %s)\n') %
(hglib.fromutf(thgversion.version()), hglib.hgversion))
(thgversion.version(), hglib.hgversion))
if not ui.quiet:
ui.write(shortlicense)
......
......@@ -27,7 +27,8 @@ class TagDialog(QDialog):
def __init__(self, repo, tag='', rev='tip', parent=None, opts={}):
super(TagDialog, self).__init__(parent)
self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint)
self.setWindowFlags(self.windowFlags() & \
~Qt.WindowContextHelpButtonHint)
self.repo = repo
......@@ -235,7 +236,7 @@ class TagDialog(QDialog):
def add_tag(self):
local = self.local_chk.isChecked()
name = self.tag_combo.currentText()
nameutf = unicode(name).encode('utf-8')
namelocal = hglib.fromunicode(name)
rev = hglib.fromunicode(self.rev_text.text())
force = self.replace_chk.isChecked()
english = self.eng_chk.isChecked()
......@@ -243,19 +244,19 @@ class TagDialog(QDialog):
try:
# tagging
if nameutf in self.repo.tags() and not force:
if namelocal in self.repo.tags() and not force:
raise util.Abort(_("Tag '%s' already exist") % name)
ctx = self.repo[rev]
node = ctx.node()
if not message:
msgset = keep._('Added tag %s for changeset %s')
message = (english and msgset['id'] or msgset['str']) \
% (name, str(ctx))
% (namelocal, str(ctx))
if not isinstance(message, str):
message = hglib.fromunicode(message)
self.repo.incrementBusyCount()
self.repo.tag(nameutf, node, message, local, None, None)
self.repo.tag(namelocal, node, message, local, None, None)
self.repo.decrementBusyCount()
if local:
self.localTagChanged.emit()
......@@ -270,13 +271,13 @@ class TagDialog(QDialog):
def remove_tag(self):
local = self.local_chk.isChecked()
name = self.tag_combo.currentText()
nameutf = unicode(name).encode('utf-8')
namelocal = hglib.fromunicode(name)
english = self.eng_chk.isChecked()
message = hglib.fromunicode(self.custom_text.text())
try:
# tagging
tagtype = self.repo.tagtype(nameutf)
tagtype = self.repo.tagtype(namelocal)
if local:
if tagtype != 'local':
raise util.Abort(_('tag \'%s\' is not a local tag') % name)
......@@ -285,11 +286,11 @@ class TagDialog(QDialog):
raise util.Abort(_('tag \'%s\' is not a global tag') % name)
if not message:
msgset = keep._('Removed tag %s')
message = (english and msgset['id'] or msgset['str']) % name
message = (english and msgset['id'] or msgset['str']) % namelocal
self.repo.incrementBusyCount()
node = self.repo[-1].node()
self.repo.tag(nameutf, node, message, local, None, None)
self.repo.tag(namelocal, node, message, local, None, None)
self.repo.decrementBusyCount()
if local:
self.localTagChanged.emit()
......
......@@ -228,9 +228,8 @@ def _extendrepo(repo):
@propertycache
def _thghiddentags(self):
# Assume Mercurial.ini file is in local encoding, need UTF-8
ht = self.ui.config('tortoisehg', 'hidetags', '')
return [hglib.toutf(t).strip() for t in ht.split()]
return [t.strip() for t in ht.split()]
@propertycache
def thgmqunappliedpatches(self):
......@@ -344,9 +343,8 @@ def _extendrepo(repo):
@propertycache
def deadbranches(self):
# Assume Mercurial.ini file is in local encoding, need UTF-8
db = self.ui.config('tortoisehg', 'deadbranch', '')
return [hglib.toutf(b).strip() for b in db.split(',')]
return [b.strip() for b in db.split(',')]
@propertycache
def displayname(self):
......@@ -483,7 +481,7 @@ def getcontext(repo, target):
def _extendchangectx(changectx):
class thgchangectx(changectx.__class__):
def thgtags(self):
'''Returns all unhidden tags for self in UTF-8'''
'''Returns all unhidden tags for self'''
htlist = self._repo._thghiddentags
return [tag for tag in self.tags() if tag not in htlist]
......@@ -595,10 +593,10 @@ class patchctx(object):
if msg:
msg = '\n'.join(msg)
self._node = node
self._user = user and hglib.tounicode(user) or ''
self._user = user or ''
self._date = date and util.parsedate(date) or util.makedate()
self._desc = msg and msg or ''
self._branch = branch and hglib.tounicode(branch) or ''
self._desc = msg or ''
self._branch = branch or ''
self._parents = []
self._rev = rev
for p in (p1, p2):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment