[PATCH 1 of 4] subrepo: restore the ability to double click open a dirty subrepo (fixes #5810)

2 views
Skip to first unread message

Matt Harbison

unread,
Jul 11, 2022, 4:52:05 PM7/11/22
to thg...@googlegroups.com
# HG changeset patch
# User Matt Harbison <matt_h...@yahoo.com>
# Date 1657571386 14400
# Mon Jul 11 16:29:46 2022 -0400
# Branch stable
# Node ID 7792b36071ea2841021d1f6a86a1a592f1f49717
# Parent 3cb0ce9c4db35eeb480cdf7c7577cfd80025ae90
subrepo: restore the ability to double click open a dirty subrepo (fixes #5810)

A str is already passed in by the manifest model (which is why this was only an
issue with wdir), and is also converted from bytes with `pycompat.sysstr`.

diff --git a/tortoisehg/hgqt/filedata.py b/tortoisehg/hgqt/filedata.py
--- a/tortoisehg/hgqt/filedata.py
+++ b/tortoisehg/hgqt/filedata.py
@@ -803,7 +803,9 @@

def createSubrepoData(ctx, pctx, path, status=None, rpath=None, subkind=None):
if not subkind:
- subkind = ctx.substate.get(path, hglib.nullsubrepostate)[2]
+ subkind = pycompat.sysstr(
+ ctx.substate.get(path, hglib.nullsubrepostate)[2]
+ )
# TODO: replace 'S' by subrepo's status
return SubrepoData(ctx, pctx, path, 'S', rpath, subkind)

Matt Harbison

unread,
Jul 11, 2022, 4:52:05 PM7/11/22
to thg...@googlegroups.com
# HG changeset patch
# User Matt Harbison <matt_h...@yahoo.com>
# Date 1657571553 14400
# Mon Jul 11 16:32:33 2022 -0400
# Branch stable
# Node ID e16309c7307454a2cfe048d42d80021bdfdea807
# Parent 7792b36071ea2841021d1f6a86a1a592f1f49717
subrepo: restore the ability to open the exact revision on py3

The URL was being formed as `repo:C:\repo\subrepo?b'95..29'`, causing it to open
the subrepo, but default to whatever revision is checked out.

diff --git a/tortoisehg/hgqt/filectxactions.py b/tortoisehg/hgqt/filectxactions.py
--- a/tortoisehg/hgqt/filectxactions.py
+++ b/tortoisehg/hgqt/filectxactions.py
@@ -456,7 +456,7 @@
else:
ctx = fd.rawContext()
spath = hglib.fromunicode(fd.canonicalFilePath())
- revid = ctx.substate[spath][1]
+ revid = hglib.tounicode(ctx.substate[spath][1])
link = 'repo:%s?%s' % (fd.absoluteFilePath(), revid)
self.linkActivated.emit(link)

Matt Harbison

unread,
Jul 11, 2022, 4:52:07 PM7/11/22
to thg...@googlegroups.com
# HG changeset patch
# User Matt Harbison <matt_h...@yahoo.com>
# 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())

Matt Harbison

unread,
Jul 11, 2022, 4:52:07 PM7/11/22
to thg...@googlegroups.com
# HG changeset patch
# User Matt Harbison <matt_h...@yahoo.com>
# Date 1657571819 14400
# Mon Jul 11 16:36:59 2022 -0400
# Branch stable
# Node ID 0e947eceeec07b184889a132721b48fa2c5213e1
# Parent e16309c7307454a2cfe048d42d80021bdfdea807
filedata: fix the path representation

I assume this isn't used anywhere, but in debugging for the previous few
commits, I noticed SubrepoData objects that are formatted to a string get
rendered like `<SubrepoData b'include'@dca2b3c54440>`.

diff --git a/tortoisehg/hgqt/filedata.py b/tortoisehg/hgqt/filedata.py
--- a/tortoisehg/hgqt/filedata.py
+++ b/tortoisehg/hgqt/filedata.py
@@ -115,7 +115,9 @@

def __repr__(self):
return '<%s %s@%s>' % (self.__class__.__name__,
- posixpath.join(self._rpath, self._wfile),
+ hglib.tounicode(
+ posixpath.join(self._rpath, self._wfile)
+ ),
self._ctx)

def isLoaded(self):

Yuya Nishihara

unread,
Jul 11, 2022, 5:31:30 PM7/11/22
to Matt Harbison, thg...@googlegroups.com
On Mon, 11 Jul 2022 16:51:59 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_h...@yahoo.com>
> # Date 1657571386 14400
> # Mon Jul 11 16:29:46 2022 -0400
> # Branch stable
> # Node ID 7792b36071ea2841021d1f6a86a1a592f1f49717
> # Parent 3cb0ce9c4db35eeb480cdf7c7577cfd80025ae90
> subrepo: restore the ability to double click open a dirty subrepo (fixes #5810)

Queued for stable, thanks.

Yuya Nishihara

unread,
Jul 11, 2022, 5:31:31 PM7/11/22
to Matt Harbison, thg...@googlegroups.com
Returning unicode from repr() may sometimes make Python 2 unhappy, but who
cares. :p
Reply all
Reply to author
Forward
0 new messages