Skip to content

Commit

Permalink
localrepo: set files to empty for subtree shallow copy commits
Browse files Browse the repository at this point in the history
Summary: For subtree shallow copy commit, we don't traverse the tree to find all the files. So the "files" list in the commit text will be empty for pure subtree shallow copy. Further more, we want to make the "files" list empty for any commits that contains subtree shallow copy, since the "files" list will not have all the changed files if the commit contains a shallow copy.

Reviewed By: muirdm

Differential Revision: D66193902

fbshipit-source-id: 3aaf5a95533112060fd52d6c69b2e2ba0c0efe7d
  • Loading branch information
zzl0 authored and facebook-github-bot committed Nov 22, 2024
1 parent 4289d92 commit 5c212f2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
7 changes: 7 additions & 0 deletions eden/scm/sapling/localrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
from .i18n import _, _n
from .node import bin, hex, nullhex, nullid
from .pycompat import range
from .utils import subtreeutil

release = lockmod.release
urlerr = util.urlerr
Expand Down Expand Up @@ -2825,6 +2826,12 @@ def commitctx(self, ctx, error=False):
extra = ctx.extra().copy()
if isgit:
git.update_extra_with_git_committer(self.ui, ctx, extra)

if subtreeutil.extra_contains_shallow_copy(extra):
# the file list can be large for a shallow copy, so don't
# put it in the files of commit text
files = []

n = self.changelog.add(
mn,
files,
Expand Down
14 changes: 14 additions & 0 deletions eden/scm/sapling/utils/subtreeutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,20 @@ def contains_shallow_copy(repo, node):
return False


def extra_contains_shallow_copy(extra) -> bool:
"""Check if the given commitctx extra contains any shallow copy metadata.
N.B. This function does not apply to "v0" subtree metadata because "v0" does
not have shallow copy type. It is used for newly incoming commits.
"""
shallow_copy_key = BranchType.SHALLOW_COPY.to_key()
if metadata_list := _get_subtree_metadata(extra, SUBTREE_KEY):
for metadata in metadata_list:
if shallow_copy_key in metadata:
return True
return False


def check_commit_splitability(repo, node):
"""Check if the given commit can be split into multiple commits.
Expand Down
29 changes: 29 additions & 0 deletions eden/scm/tests/test-subtree-shallow-copy.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
$ setconfig diff.git=True
$ setconfig subtree.copy-reuse-tree=True
$ setconfig subtree.allow-any-source-commit=True

test subtree copy
$ newclientrepo
$ drawdag <<'EOS'
> B # B/foo/x = bbb\n
> |
> A # A/foo/x = aaa\n
> # drawdag.defaultfiles=false
> EOS
$ hg go $B -q
$ hg subtree cp -r $A --from-path foo --to-path bar -m "subtree copy foo -> bar"
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ hg dbsh -c 'print(repo["."].extra())'
{'branch': 'default', 'test_subtree': '[{"copies":[{"from_commit":"d908813f0f7c9078810e26aad1e37bdb32013d4b","from_path":"foo","to_path":"bar"}],"v":1}]'}
$ hg dbsh -c 'print(repo["."].changeset().files)'
()

files list is still empty after amending the shallow copy commit
$ echo ccc >> bar/x
$ hg amend
$ hg dbsh -c 'print(repo["."].extra())'
{'branch': 'default', 'amend_source': '075709eca377ab1f8a1e6a31b7970d26ff9ec935', 'test_subtree': '[{"copies":[{"from_commit":"d908813f0f7c9078810e26aad1e37bdb32013d4b","from_path":"foo","to_path":"bar"}],"v":1}]'}
$ hg dbsh -c 'print(repo["."].changeset().files)'
()
$ hg dbsh -c 'print(repo["."].files())'
['bar/x']

0 comments on commit 5c212f2

Please sign in to comment.