Mercurial > hg
diff mercurial/manifest.py @ 51785:bcb825bf0c5e
manifest: add a read_delta_new_entries method
This new method have a well defined semantic and can be adjusted by narrow as it
needs.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 06 Aug 2024 02:12:08 +0200 |
parents | a891347058e7 |
children | 9af1acc1ffab |
line wrap: on
line diff
--- a/mercurial/manifest.py Thu Aug 01 13:15:54 2024 +0200 +++ b/mercurial/manifest.py Tue Aug 06 02:12:08 2024 +0200 @@ -2090,6 +2090,10 @@ """ return self.get(b'', node) + @property + def narrowed(self): + return not (self._narrowmatch is None or self._narrowmatch.always()) + def get( self, tree: bytes, node: bytes, verify: bool = True ) -> AnyManifestCtx: @@ -2317,6 +2321,20 @@ md.set(f, new_node, new_flag) return md + def read_delta_new_entries(self, *, shallow=False) -> ManifestDict: + """see `interface.imanifestrevisionbase` documentations""" + # If we are using narrow, returning a delta against an arbitrary + # changeset might return file outside the narrowspec. This can create + # issue when running validation server side with strict security as + # push from low priviledge usage might be seen as adding new revision + # for files they cannot touch. So we are strict if narrow is involved. + if self._manifestlog.narrowed: + return self.read_delta_parents(shallow=shallow, exact=True) + store = self._storage() + r = store.rev(self._node) + d = mdiff.patchtext(store.revdiff(store.deltaparent(r), r)) + return manifestdict(store.nodeconstants.nodelen, d) + def find(self, key: bytes) -> Tuple[bytes, bytes]: return self.read().find(key) @@ -2576,6 +2594,23 @@ md.set(f, new_node, new_flag) return md + def read_delta_new_entries( + self, *, shallow: bool = False + ) -> AnyManifestDict: + """see `interface.imanifestrevisionbase` documentations""" + # If we are using narrow, returning a delta against an arbitrary + # changeset might return file outside the narrowspec. This can create + # issue when running validation server side with strict security as + # push from low priviledge usage might be seen as adding new revision + # for files they cannot touch. So we are strict if narrow is involved. + if self._manifestlog.narrowed: + return self.read_delta_parents(shallow=shallow, exact=True) + # delegate to existing another existing method for simplicity + store = self._storage() + r = store.rev(self._node) + bases = (store.deltaparent(r),) + return self.read_any_fast_delta(bases, shallow=shallow)[1] + def readfast(self, shallow=False) -> AnyManifestDict: """Calls either readdelta or read, based on which would be less work. readdelta is called if the delta is against the p1, and therefore can be