Skip to content

Commit

Permalink
subtree: use contains_shallow_copy() in ctx.files()
Browse files Browse the repository at this point in the history
Summary:
For subtree commits, we only need to compute the file list if it contains shallow copy. So this diffs
check that to determine if the manifest diff is needed. Later, we will make `self._changeset.files`
an empty list if the commit contains a shallow copy, and in long-term, we will remove the file list
from commit text.

Reviewed By: muirdm

Differential Revision: D65462388

fbshipit-source-id: c85e8fa8a1d45807dd100d39990e8ea0b828eceb
  • Loading branch information
zzl0 authored and facebook-github-bot committed Nov 5, 2024
1 parent bf16e55 commit b3d4e5f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 4 additions & 5 deletions eden/scm/sapling/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
wdirrev,
)
from .pycompat import encodeutf8, isint, range
from .utils.subtreeutil import SUBTREE_BRANCH_KEY
from .utils import subtreeutil

filectx_or_bytes = Union["basefilectx", bytes]

Expand Down Expand Up @@ -591,10 +591,9 @@ def files(self):
# The following cases does not provide "files" in commit message,
# run diff to get it:
# - git repo
# - O(1) subtree copy
if (
git.isgitformat(self._repo)
or SUBTREE_BRANCH_KEY in self._changeset.extra
# - subtree shallow copy
if git.isgitformat(self._repo) or subtreeutil.contains_shallow_copy(
self._repo, self.node()
):
files = sorted(self.manifest().diff(self.p1().manifest()).keys())
return files
Expand Down
8 changes: 8 additions & 0 deletions eden/scm/sapling/utils/subtreeutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,14 @@ def is_source_commit_allowed(ui, source_ctx) -> bool:
return False


def contains_shallow_copy(repo, node):
branches = get_subtree_branches(repo, node)
for b in branches:
if b.branch_type == BranchType.SHALLOW_COPY:
return True
return False


def check_commit_splitability(repo, node):
"""Check if the given commit can be split into multiple commits.
Expand Down

0 comments on commit b3d4e5f

Please sign in to comment.