Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/subrepo.py @ 51810:a53162bd73ed
subrepo: drop the default value of None for the archive matcher
This was flagged by pytype after adding hints to `match.subdirmatcher` that it
takes a non-optional matcher. That matcher argument is used without a guard in
the subdirmatcher constructor, so that's the correct restriction.
I don't think this fixes a bug in practice because the only way these are
invoked is either by a parent `hgsubrepo.archive()`, `archival.archive()`, or
the largefiles override of these. The `hgsubrepo.archive()` case (and the
largefiles override) uses what the caller provided, so the caller will
eventually be `archival.archive()` (or the largfiles override) up the call
chain. The `archival.archive()` method also has None for its matcher's default
arg. However, the three callers of that (`commands.archive()`,
`webcommands.archive()`, and `extdiff.snapshot()`) all provide a matcher
argument, so the None case can never occur unless a 3rd party extension swaps it
for None. Sadly, we can't make the argument on the `archival.archive()`
non-optional because there is a kwarg prior to it.
Even though the largefiles override of `archival.archive()` is provided a valid
matcher, we duplicate the internal creation of the matcher that the original
`archival.archive()` does for consistency. By eliminating an impossible to hit
case, we can simplify some of the subrepo code too, by dropping unreachable
code.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Thu, 01 Aug 2024 01:52:11 -0400 |
parents | ca7bde5dbafb |
children | a1e4fa9330d8 |
comparison
equal
deleted
inserted
replaced
51809:9b8c71d0b785 | 51810:a53162bd73ed |
---|---|
361 | 361 |
362 def printfiles(self, ui, m, uipathfn, fm, fmt, subrepos): | 362 def printfiles(self, ui, m, uipathfn, fm, fmt, subrepos): |
363 """handle the files command for this subrepo""" | 363 """handle the files command for this subrepo""" |
364 return 1 | 364 return 1 |
365 | 365 |
366 def archive(self, archiver, prefix, match=None, decode=True): | 366 def archive(self, archiver, prefix, match, decode=True): |
367 if match is not None: | 367 files = [f for f in self.files() if match(f)] |
368 files = [f for f in self.files() if match(f)] | |
369 else: | |
370 files = self.files() | |
371 total = len(files) | 368 total = len(files) |
372 relpath = subrelpath(self) | 369 relpath = subrelpath(self) |
373 progress = self.ui.makeprogress( | 370 progress = self.ui.makeprogress( |
374 _(b'archiving (%s)') % relpath, unit=_(b'files'), total=total | 371 _(b'archiving (%s)') % relpath, unit=_(b'files'), total=total |
375 ) | 372 ) |
650 _(b'warning: error "%s" in subrepository "%s"\n') | 647 _(b'warning: error "%s" in subrepository "%s"\n') |
651 % (inst, subrelpath(self)) | 648 % (inst, subrelpath(self)) |
652 ) | 649 ) |
653 | 650 |
654 @annotatesubrepoerror | 651 @annotatesubrepoerror |
655 def archive(self, archiver, prefix, match=None, decode=True): | 652 def archive(self, archiver, prefix, match, decode=True): |
656 self._get(self._state + (b'hg',)) | 653 self._get(self._state + (b'hg',)) |
657 files = self.files() | 654 files = [f for f in self.files() if match(f)] |
658 if match: | |
659 files = [f for f in files if match(f)] | |
660 rev = self._state[1] | 655 rev = self._state[1] |
661 ctx = self._repo[rev] | 656 ctx = self._repo[rev] |
662 scmutil.prefetchfiles( | 657 scmutil.prefetchfiles( |
663 self._repo, [(ctx.rev(), scmutil.matchfiles(self._repo, files))] | 658 self._repo, [(ctx.rev(), scmutil.matchfiles(self._repo, files))] |
664 ) | 659 ) |
1909 if kind == stat.S_IFDIR: | 1904 if kind == stat.S_IFDIR: |
1910 self.wvfs.rmtree(f) | 1905 self.wvfs.rmtree(f) |
1911 else: | 1906 else: |
1912 self.wvfs.unlink(f) | 1907 self.wvfs.unlink(f) |
1913 | 1908 |
1914 def archive(self, archiver, prefix, match=None, decode=True): | 1909 def archive(self, archiver, prefix, match, decode=True): |
1915 total = 0 | 1910 total = 0 |
1916 source, revision = self._state | 1911 source, revision = self._state |
1917 if not revision: | 1912 if not revision: |
1918 return total | 1913 return total |
1919 self._fetch(source, revision) | 1914 self._fetch(source, revision) |
1930 progress.update(0) | 1925 progress.update(0) |
1931 for info in tar: | 1926 for info in tar: |
1932 if info.isdir(): | 1927 if info.isdir(): |
1933 continue | 1928 continue |
1934 bname = pycompat.fsencode(info.name) | 1929 bname = pycompat.fsencode(info.name) |
1935 if match and not match(bname): | 1930 if not match(bname): |
1936 continue | 1931 continue |
1937 if info.issym(): | 1932 if info.issym(): |
1938 data = info.linkname | 1933 data = info.linkname |
1939 else: | 1934 else: |
1940 f = tar.extractfile(info) | 1935 f = tar.extractfile(info) |