D10179: subrepo: handle unexpected file types from git gracefully

mharbison72 (Matt Harbison) phabricator at mercurial-scm.org
Fri Mar 12 18:09:50 UTC 2021


mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This was flagged by pytype because `tar.extractfile(...)` can return None if the
  entry is not a file or symlink.  I don't think that git supports other types,
  but better safe than sorry.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

REVISION DETAIL
  https://phab.mercurial-scm.org/D10179

AFFECTED FILES
  mercurial/subrepo.py

CHANGE DETAILS

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -1876,7 +1876,12 @@
             if info.issym():
                 data = info.linkname
             else:
-                data = tar.extractfile(info).read()
+                f = tar.extractfile(info)
+                if f:
+                    data = f.read()
+                else:
+                    self.ui.warn(_(b'skipping "%s" (unknown type)') % bname)
+                    continue
             archiver.addfile(prefix + bname, info.mode, info.issym(), data)
             total += 1
             progress.increment()



To: mharbison72, #hg-reviewers
Cc: mercurial-patches, mercurial-devel


More information about the Mercurial-devel mailing list