Skip to content

Commit

Permalink
graft: skip ungraftable subtree copy and merge revisions
Browse files Browse the repository at this point in the history
Summary:
Grafting subtree copy (branch) and merge commits doesn't seem particularly useful,
as grafting an O(1) copy commit could turn it into an O(n) operation. This diff skips
subtree copy and merge commits, similar to how merge commits are skipped.

Reviewed By: muirdm

Differential Revision: D67902937

fbshipit-source-id: 50b11c6dfaf97ec62d3de7fc96adab8641988b6f
  • Loading branch information
zzl0 authored and facebook-github-bot committed Jan 9, 2025
1 parent b04c280 commit c922b44
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
10 changes: 10 additions & 0 deletions eden/scm/sapling/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2598,6 +2598,16 @@ def _dograft(ui, repo, *revs, **opts):
for rev in repo.revs("%ld and merge()", revs):
ui.warn(_("skipping ungraftable merge revision %d\n") % rev)
skipped.add(rev)
# check subtree copy and merge
for rev in revs:
if rev in skipped:
continue
ctx = repo[rev]
if subtreeutil.get_subtree_metadata(ctx.extra()):
ui.warn(
_("skipping ungraftable subtree copy and merge revision %s\n") % ctx
)
skipped.add(rev)
revs = [r for r in revs if r not in skipped]
if not revs:
raise error.Abort(_("empty revision set was specified"))
Expand Down
27 changes: 27 additions & 0 deletions eden/scm/tests/test-subtree-mutation.t
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,30 @@ test split subtree copy commit
$ hg split
abort: cannot split subtree copy/merge commits
[255]

test graft subtree copy and merge commits
$ newclientrepo
$ drawdag <<'EOS'
> B # B/foo/x = 1a\n2\n3\n
> |
> A # A/foo/x = 1\n2\n3\n
> EOS
$ hg go -q $B
$ hg subtree copy -r $A --from-path foo --to-path bar -m "subtree copy foo to bar"
copying foo to bar
$ hg subtree merge -r $B --from-path foo --to-path bar -q
$ hg ci -m "subtree merge foo to bar"
$ hg log -G -T '{node|short} {desc|firstline}'
@ 5d2f9c7b4852 subtree merge foo to bar
o ee6785824a72 subtree copy foo to bar
o c4fbbcdf676b B
o b4cb27eee4e2 A
$ hg go -q $B
$ hg graft 5d2f9c7b4852 ee6785824a72
skipping ungraftable subtree copy and merge revision 5d2f9c7b4852
skipping ungraftable subtree copy and merge revision ee6785824a72
abort: empty revision set was specified
[255]

0 comments on commit c922b44

Please sign in to comment.