Add orig_parent to create change descriptions.

Bug: 1426333
Change-Id: I9a199d98aad7ca5133dfa85dd632ffc22f89e421
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4370432
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Joanna Wang <jojwang@chromium.org>
changes/32/4370432/4
Joanna Wang 3 years ago committed by LUCI CQ
parent cf46585793
commit 05b60349bd

@ -1686,14 +1686,29 @@ class Changelist(object):
# branch/change.
return refspec_opts
def PrepareSquashedCommit(self, options, parent, end_commit=None):
# type: (optparse.Values, str, Optional[str]) -> _NewUpload()
"""Create a squashed commit to upload."""
def PrepareSquashedCommit(self,
options,
parent,
orig_parent,
end_commit=None):
# type: (optparse.Values, str, str, Optional[str]) -> _NewUpload()
"""Create a squashed commit to upload.
Args:
parent: The commit to use as the parent for the new squashed.
orig_parent: The commit that is an actual ancestor of `end_commit`. It
is part of the same original tree as end_commit, which does not
contain squashed commits. This is used to create the change
description for the new squashed commit with:
`git log orig_parent..end_commit`.
end_commit: The commit to use as the end of the new squashed commit.
"""
if end_commit is None:
end_commit = RunGit(['rev-parse', self.branchref]).strip()
reviewers, ccs, change_desc = self._PrepareChange(options, parent,
reviewers, ccs, change_desc = self._PrepareChange(options, orig_parent,
end_commit)
latest_tree = RunGit(['rev-parse', end_commit + ':']).strip()
with gclient_utils.temporary_file() as desc_tempfile:
@ -4870,6 +4885,7 @@ def UploadAllSquashed(options, orig_args):
# We can only support external changes when we're only uploading one
# branch.
parent = cl._UpdateWithExternalChanges() if len(ordered_cls) == 1 else None
orig_parent = None
if parent is None:
origin = '.'
branch = cl.GetBranch()
@ -4884,6 +4900,9 @@ def UploadAllSquashed(options, orig_args):
if upstream_branch in ['master', 'main']:
parent = cl.GetCommonAncestorWithUpstream()
else:
orig_parent = scm.GIT.GetBranchConfig(settings.GetRoot(),
upstream_branch,
LAST_UPLOAD_HASH_CONFIG_KEY)
parent = scm.GIT.GetBranchConfig(settings.GetRoot(),
upstream_branch,
GERRIT_SQUASH_HASH_CONFIG_KEY)
@ -4896,6 +4915,8 @@ def UploadAllSquashed(options, orig_args):
# tree.
parent = cl.GetCommonAncestorWithUpstream()
if orig_parent is None:
orig_parent = parent
for i, cl in enumerate(ordered_cls):
# If we're in the middle of the stack, set end_commit to downstream's
# direct ancestor.
@ -4905,9 +4926,11 @@ def UploadAllSquashed(options, orig_args):
child_base_commit = None
new_upload = cl.PrepareSquashedCommit(options,
parent,
orig_parent,
end_commit=child_base_commit)
uploads_by_cl.append((cl, new_upload))
parent = new_upload.commit_to_push
orig_parent = child_base_commit
# Create refspec options
cl, new_upload = uploads_by_cl[-1]

@ -1653,11 +1653,16 @@ class TestGitCl(unittest.TestCase):
git_cl.UploadAllSquashed(options, orig_args)
# Asserts
self.maxDiff = None
self.assertEqual(mockSquashedCommit.mock_calls, [
mock.call(options,
'current-upstream-ancestor',
'current-upstream-ancestor',
end_commit='next-upstream-ancestor'),
mock.call(options, upstream_commit_to_push, end_commit=None)
mock.call(options,
upstream_commit_to_push,
'next-upstream-ancestor',
end_commit=None)
])
expected_refspec = ('commit-to-push:refs/for/refs/heads/main%notify=NONE,'
@ -1737,8 +1742,10 @@ class TestGitCl(unittest.TestCase):
git_cl.UploadAllSquashed(options, orig_args)
# Asserts
self.assertEqual(mockSquashedCommit.mock_calls,
[mock.call(options, 'external-commit', end_commit=None)])
self.assertEqual(mockSquashedCommit.mock_calls, [
mock.call(
options, 'external-commit', 'external-commit', end_commit=None)
])
expected_refspec = ('commit-to-push:refs/for/refs/heads/main%notify=NONE,'
'm=honk_stonk,topic=circus,hashtag=cow')
@ -1760,9 +1767,12 @@ class TestGitCl(unittest.TestCase):
git_cl.UploadAllSquashed(options, orig_args)
# Asserts
self.assertEqual(
mockSquashedCommit.mock_calls,
[mock.call(options, 'current-upstream-ancestor', end_commit=None)])
self.assertEqual(mockSquashedCommit.mock_calls, [
mock.call(options,
'current-upstream-ancestor',
'current-upstream-ancestor',
end_commit=None)
])
@mock.patch(
'git_cl.Changelist._GerritCommitMsgHookCheck', lambda offer_removal: None)
@ -4005,6 +4015,7 @@ class ChangelistTest(unittest.TestCase):
mockPrepareChange.return_value = (reviewers, ccs, change_desc)
parent_hash = 'upstream-gerrit-hash'
parent_orig_hash = 'upstream-last-upload-hash'
parent_hash_root = 'root-commit'
hash_to_push = 'new-squash-hash'
hash_to_push_root = 'new-squash-hash-root'
@ -4028,13 +4039,14 @@ class ChangelistTest(unittest.TestCase):
cl = git_cl.Changelist(branchref=branchref)
options = optparse.Values()
new_upload = cl.PrepareSquashedCommit(options, parent_hash)
new_upload = cl.PrepareSquashedCommit(options, parent_hash,
parent_orig_hash)
self.assertEqual(new_upload.reviewers, reviewers)
self.assertEqual(new_upload.ccs, ccs)
self.assertEqual(new_upload.commit_to_push, hash_to_push)
self.assertEqual(new_upload.new_last_uploaded_commit, end_hash)
self.assertEqual(new_upload.change_desc, change_desc)
mockPrepareChange.assert_called_with(options, parent_hash, end_hash)
mockPrepareChange.assert_called_with(options, parent_orig_hash, end_hash)
@mock.patch('git_cl.Settings.GetRoot', return_value='')
@mock.patch('git_cl.Changelist.GetMostRecentPatchset', return_value=2)

Loading…
Cancel
Save