[PATCH STABLE] hglib: prevent crashing when using the remotefilelog extension

3 views
Skip to first unread message

Kévin Lévesque

unread,
May 17, 2021, 4:01:47 PM5/17/21
to TortoiseHg Developers
# HG changeset patch
# User Kévin Lévesque <klev...@innovmetric.com>
# Date 1621277647 14400
#      Mon May 17 14:54:07 2021 -0400
# Branch stable
# Node ID cec3af5ff91946641ebc2cef4d2c41626276d550
# Parent  9443099d7c4fef0e727ab7f3e3dd61b4cb16faa4
hglib: prevent crashing when using the remotefilelog extension

When using the remotefilelog extension, the _filelog attribute is not available.
This result in a crash. To prevent this, we return a big number instead.
We cannot fallback to fctx.size() as it would fetch the file and freeze the UI
while it does so.

diff -r 9443099d7c4f -r cec3af5ff919 tortoisehg/util/hglib.py
--- a/tortoisehg/util/hglib.py Tue May 11 19:40:08 2021 +0900
+++ b/tortoisehg/util/hglib.py Mon May 17 14:54:07 2021 -0400
@@ -936,13 +936,19 @@
 def getestimatedsize(fctx):
     # type: (...) -> int
     """Return the size of the given fctx without loading the revision text"""
+    FILE_SIZE_UNKNOWN = 2147483647
+    
     if fctx.rev() is None:
         return fctx.size()
     else:
         # fctx.size() can read all data into memory in rename cases so
         # we read the size directly from the filelog, this is deeper
         # under the API than I prefer to go, but seems necessary
-        return fctx._filelog._revlog.rawsize(fctx.filerev())
+        try:
+            return fctx._filelog._revlog.rawsize(fctx.filerev())
+        except AttributeError:
+            # _filelog is not available when using the remotefilelog extension on a shallow repo
+            return FILE_SIZE_UNKNOWN
 
 def get_revision_desc(fctx, curpath=None):
     # type: (Any, Optional[bytes]) -> pycompat.unicode

Yuya Nishihara

unread,
May 18, 2021, 5:42:25 AM5/18/21
to thg...@googlegroups.com, Kévin Lévesque
On Mon, 17 May 2021 12:32:53 -0700 (PDT), Kévin Lévesque wrote:
> # HG changeset patch
> # User Kévin Lévesque <klev...@innovmetric.com>
> # Date 1621277647 14400
> # Mon May 17 14:54:07 2021 -0400
> # Branch stable
> # Node ID cec3af5ff91946641ebc2cef4d2c41626276d550
> # Parent 9443099d7c4fef0e727ab7f3e3dd61b4cb16faa4
> hglib: prevent crashing when using the remotefilelog extension

Queued for stable, thanks.

Next time, please consider using the patchbomb extension or TortoiseHg
email dialog. Otherwise your mailer would reformat the patch content.

https://www.mercurial-scm.org/wiki/ContributingChanges#Emailing_patches

> + try:
> + return fctx._filelog._revlog.rawsize(fctx.filerev())
> + except AttributeError:

It's better to minimize the scope of AttributeError, but I'm okay with this.
Reply all
Reply to author
Forward
0 new messages