# Date 1657573712 14400
# Mon Jul 11 17:08:32 2022 -0400
# Branch stable
# Node ID 7d64976e909bf1add8956e870588d046956d60e5
# Parent 0e947eceeec07b184889a132721b48fa2c5213e1
subrepo: fix bytes/str mismatches when displaying subrepo edge cases
This started by noticing that `sactual` is initialized to str, but later set to
bytes from a core API, and then compared against `srev`, which was also bytes
from a core API. But since `genSubrepoRevChangedDescription()` mostly does str
operations, convert all of these to str, and then convert back to bytes as
needed to call core APIs. For all of the changes, it appears that the broken
paths were limited to newly added, removed, and deleted subrepos.
diff --git a/tortoisehg/hgqt/filedata.py b/tortoisehg/hgqt/filedata.py
--- a/tortoisehg/hgqt/filedata.py
+++ b/tortoisehg/hgqt/filedata.py
@@ -27,6 +27,15 @@
from tortoisehg.util.i18n import _
from tortoisehg.hgqt import fileencoding
+if hglib.TYPE_CHECKING:
+ from typing import (
+ Any,
+ List,
+ Text,
+ Tuple,
+ )
+
+
forcedisplaymsg = _('Display the file anyway')
class _BadContent(Exception):
@@ -583,11 +592,12 @@
try:
def genSubrepoRevChangedDescription(subrelpath, sfrom, sto,
repo):
+ # type: (bytes, Text, Text, Any) -> Tuple[List[Text], Text]
"""Generate a subrepository revision change description"""
out = []
def getLog(_ui, srepo, opts):
if srepo is None:
- return _('changeset: %s') % opts['rev'][0][:12]
+ return _('changeset: %s') % hglib.tounicode(opts['rev'][0][:12])
_ui.pushbuffer()
logOutput = b''
try:
@@ -602,16 +612,17 @@
# case, add a warning to the output, but try to
# get the revision information anyway
for n, rev in enumerate(opts['rev']):
- if rev.endswith('+'):
+ if rev.endswith(b'+'):
logOutput += hglib.fromunicode(
_('[WARNING] Invalid subrepo '
- 'revision ID:\n\t%s\n\n') % rev)
+ 'revision ID:\n\t%s\n\n')
+ % hglib.tounicode(rev))
opts['rev'][n] = rev[:-1]
commands.log(_ui, srepo, **opts)
logOutput += _ui.popbuffer()
return hglib.tounicode(logOutput)
- opts = {'date':None, 'rev':[sfrom]}
+ opts = {'date':None, 'rev':[hglib.fromunicode(sfrom)]}
subabspath = os.path.join(repo.root, subrelpath)
missingsub = srepo is None or not os.path.isdir(subabspath)
sfromlog = ''
@@ -636,7 +647,8 @@
+ u'\n\n')
out.append(_('Previously the subrepository was '
'at the following revision:') + u'\n\n')
- subinfo = getLog(_ui, srepo, {'rev': [sfrom]})
+ subinfo = getLog(_ui, srepo,
+ {'rev': [hglib.fromunicode(sfrom)]})
slog = hglib.tounicode(subinfo)
out.append(slog)
return out, sstatedesc
@@ -684,7 +696,7 @@
'directory.') + '\n'
else:
try:
- opts['rev'] = [sto]
+ opts['rev'] = [hglib.fromunicode(sto)]
stolog = getLog(_ui, srepo, opts)
except error.RepoError:
header = _(
@@ -702,7 +714,9 @@
return out, sstatedesc
- srev = ctx.substate.get(wfile, hglib.nullsubrepostate)[1]
+ srev = hglib.tounicode(
+ ctx.substate.get(wfile, hglib.nullsubrepostate)[1]
+ )
srepo = None
subabspath = os.path.join(ctx.repo().root, wfile)
sactual = ''
@@ -712,7 +726,7 @@
if isinstance(sub, subrepo.hgsubrepo):
srepo = sub._repo
if srepo is not None:
- sactual = srepo[b'.'].hex()
+ sactual = hglib.tounicode(srepo[b'.'].hex())
else:
self.error = _('Not a Mercurial subrepo, not '
'previewable')
@@ -747,7 +761,9 @@
sstatedesc = 'changed'
if ctx.rev() is not None:
- sparent = ctx2.substate.get(wfile, hglib.nullsubrepostate)[1]
+ sparent = hglib.tounicode(
+ ctx2.substate.get(wfile, hglib.nullsubrepostate)[1]
+ )
subrepochange, sstatedesc = \
genSubrepoRevChangedDescription(wfile,
sparent, srev, ctx.repo())