Skip to content

Commit

Permalink
subtree: graft supports '-m' option for user-provided messages
Browse files Browse the repository at this point in the history
Summary: This diff allows users to provide commit message via command line with '-m' option.

Reviewed By: muirdm

Differential Revision: D63050338

fbshipit-source-id: e6dc3e3d300f9d58b104bcce63c3fb9e1925b831
  • Loading branch information
zzl0 authored and facebook-github-bot committed Sep 24, 2024
1 parent bfcc97b commit a38deb6
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
23 changes: 15 additions & 8 deletions eden/scm/sapling/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2691,7 +2691,7 @@ def _dograft(ui, repo, *revs, **opts):

# commit
editor = cmdutil.getcommiteditor(editform="graft", **opts)
message = _makegraftmessage(ctx, opts)
message = _makegraftmessage(repo, ctx, opts)
node = repo.commit(
text=message, user=user, date=date, extra=extra, editor=editor
)
Expand All @@ -2708,8 +2708,12 @@ def _dograft(ui, repo, *revs, **opts):
return 0


def _makegraftmessage(ctx, opts):
description = ctx.description()
def _makegraftmessage(repo, ctx, opts):
if logmessage := cmdutil.logmessage(repo, opts):
description, is_from_ctx = logmessage, False
else:
description, is_from_ctx = ctx.description(), True

message = []
if opts.get("from_path"):
# For xdir grafts, include "grafted from" breadcrumb by default.
Expand All @@ -2718,11 +2722,14 @@ def _makegraftmessage(ctx, opts):
for f, t in zip(opts.get("from_path"), opts.get("to_path")):
message.append("- Grafted path %s to %s" % (f, t))

try:
title, rest = description.split("\n", 1)
description = f'Graft "{title}"\n{rest}'
except ValueError:
description = f'Graft "{description}"'
# only update the title if it is from original change context,
# we don't update the user provided title
if is_from_ctx:
try:
title, rest = description.split("\n", 1)
description = f'Graft "{title}"\n{rest}'
except ValueError:
description = f'Graft "{description}"'
else:
if opts.get("log"):
message.append("(grafted from %s)" % ctx.hex())
Expand Down
1 change: 1 addition & 0 deletions eden/scm/sapling/commands/subtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def subtree_copy(ui, repo, *args, **opts):
_("record the current user as committer"),
),
]
+ commitopts
+ commitopts2
+ mergetoolopts
+ dryrunopts
Expand Down
4 changes: 2 additions & 2 deletions eden/scm/sapling/ext/fbcodereview.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ def makebackoutmessage(orig, repo, message: str, node):
return message


def makegraftmessage(orig, ctx, opts):
message = orig(ctx, opts)
def makegraftmessage(orig, repo, ctx, opts):
message = orig(repo, ctx, opts)
if not opts.get("from_path"):
return message

Expand Down
36 changes: 36 additions & 0 deletions eden/scm/tests/test-subtree.t
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,42 @@ test subtree graft
-3
+3a

test 'subtree graft -m'
$ newclientrepo
$ drawdag <<'EOS'
> C # C/foo/x = 1a\n2\n3a\n
> |
> B # B/foo/x = 1a\n2\n3\n
> |
> A # A/foo/x = 1\n2\n3\n
> # drawdag.defaultfiles=false
> EOS
$ hg go $C -q
$ hg subtree copy -r $B --from-path foo --to-path bar -m 'subtree copy foo -> bar'
1 files updated, 0 files merged, 0 files removed, 0 files unresolved

$ hg subtree graft -r $C --from-path foo --to-path bar -m "new C"
grafting 78072751cf70 "C"
$ hg show
commit: 6eac9525eeb2
user: test
date: Thu Jan 01 00:00:00 1970 +0000
files: bar/x
description:
new C

Grafted from 78072751cf70f1ca47671c625f3b2d7f86f45f00
- Grafted path foo to bar


diff --git a/bar/x b/bar/x
--- a/bar/x
+++ b/bar/x
@@ -1,3 +1,3 @@
1a
2
-3
+3a

test subtree merge
$ newclientrepo
Expand Down

0 comments on commit a38deb6

Please sign in to comment.