push: avoid rebasing when we know there are no conflicts

When pushing multiple commits, push would do one rebase
per commit. This changes it track the files that have been
changed as part of the push and only perform a rebase if
the commit touches a file that has been changed previously.

On our repo, push used to take 25 seconds per commit. With
this change it takes closer to 10 seconds per commit (if
there are no conflicts).
This commit is contained in:
Durham Goode 2013-01-02 17:54:30 -08:00
parent 90870aa082
commit ee7e5eee75
2 changed files with 63 additions and 21 deletions

View File

@ -211,6 +211,7 @@ def push(repo, dest, force, revs):
tip_ctx = repo[outgoing[-1]].p1()
svnbranch = tip_ctx.branch()
modified_files = {}
for i in range(len(outgoing) - 1, -1, -1):
# 2. Pick the oldest changeset that needs to be pushed
current_ctx = repo[outgoing[i]]
@ -223,29 +224,36 @@ def push(repo, dest, force, revs):
return 0
# 3. Move the changeset to the tip of the branch if necessary
util.swap_out_encoding(old_encoding)
try:
def extrafn(ctx, extra):
extra['branch'] = ctx.branch()
ui.status('rebasing %s onto %s \n' % (current_ctx, tip_ctx))
hgrebase.rebase(ui, repo,
dest=node.hex(tip_ctx.node()),
rev=[node.hex(current_ctx.node())],
extrafn=extrafn, keep=True)
finally:
util.swap_out_encoding()
# Don't trust the pre-rebase repo and context.
repo = getlocalpeer(ui, {}, meta.path)
tip_ctx = repo[tip_ctx.node()]
for c in tip_ctx.descendants():
rebasesrc = c.extra().get('rebase_source')
if rebasesrc and node.bin(rebasesrc) == current_ctx.node():
current_ctx = c
temporary_commits.append(c.node())
conflicts = False
for file in current_ctx.files():
if file in modified_files:
conflicts = True
break
if conflicts or current_ctx.branch() != svnbranch:
util.swap_out_encoding(old_encoding)
try:
def extrafn(ctx, extra):
extra['branch'] = ctx.branch()
ui.status('rebasing %s onto %s \n' % (current_ctx, tip_ctx))
hgrebase.rebase(ui, repo,
dest=node.hex(tip_ctx.node()),
rev=[node.hex(current_ctx.node())],
extrafn=extrafn, keep=True)
finally:
util.swap_out_encoding()
# Don't trust the pre-rebase repo and context.
repo = getlocalpeer(ui, {}, meta.path)
tip_ctx = repo[tip_ctx.node()]
for c in tip_ctx.descendants():
rebasesrc = c.extra().get('rebase_source')
if rebasesrc and node.bin(rebasesrc) == current_ctx.node():
current_ctx = c
temporary_commits.append(c.node())
break
# 4. Push the changeset to subversion
tip_hash = hashes[tip_ctx.node()][0]
try:
@ -268,6 +276,11 @@ def push(repo, dest, force, revs):
if c.node() in hashes and c.branch() == svnbranch:
tip_ctx = c
# Remember what files have been modified since the
# whole push started.
for file in c.files():
modified_files[file] = True
# 7. Rebase any children of the commit we just pushed
# that are not in the outgoing set
for c in original_ctx.children():

View File

@ -551,6 +551,35 @@ class PushTests(test_util.TestBase):
self.assertEqual(commit1.files(), ['gamma', ])
self.assertFalse(commit1.mutable())
def test_push_two_that_modify_same_file(self):
'''
Push performs a rebase if two commits touch the same file.
This test verifies that code path works.
'''
oldlen = len(self.repo)
oldtiphash = self.repo['default'].node()
changes = [('gamma', 'gamma', 'sometext')]
newhash = self.commitchanges(changes)
changes = [('gamma', 'gamma', 'sometext\n moretext'),
('delta', 'delta', 'sometext\n moretext'),
]
newhash = self.commitchanges(changes)
repo = self.repo
hg.update(repo, newhash)
commands.push(repo.ui, repo)
self.assertEqual(len(self.repo), oldlen + 2)
# verify that both commits are pushed
commit1 = self.repo['tip']
self.assertEqual(commit1.files(), ['delta', 'gamma'])
self.assertFalse(commit1.mutable())
commit2 = commit1.parents()[0]
self.assertEqual(commit2.files(), ['gamma'])
self.assertFalse(commit2.mutable())
def suite():
test_classes = [PushTests, ]