Skip to content

Commit

Permalink
[git-rebase-update] Disallow git gc during git-rebase-update.
Browse files Browse the repository at this point in the history
In theory this should prevent `git rebase-update` from invoking
potentially expensive `git gc` operations after every `git rebase`
(ideally once per branch, but sometimes as many as three per branch (!)).

This has outsized effects as the size of the repo or number of branches
increases, and additionally has penalties on Windows due to git's
POSIXey assumptions around how disk I/O works.

After doing all rebase stuff, we run `git gc --auto` from rebase-update
once (assuming we were successful; if the command failed then we don't
run gc at all).

R=apolito@google.com

Bug: 617218
Change-Id: I37a8f7953779f15b320e4ed7bb85119cb4bb665a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2868766
Auto-Submit: Robbie Iannucci <iannucci@chromium.org>
Reviewed-by: Anthony Polito <apolito@google.com>
Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
  • Loading branch information
riannucci authored and LUCI CQ committed May 4, 2021
1 parent 0f40264 commit d3acb16
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
23 changes: 18 additions & 5 deletions git_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,15 +641,22 @@ def parse_commitrefs(*commitrefs):
RebaseRet = collections.namedtuple('RebaseRet', 'success stdout stderr')


def rebase(parent, start, branch, abort=False):
def rebase(parent, start, branch, abort=False, allow_gc=False):
"""Rebases |start|..|branch| onto the branch |parent|.
Sets 'gc.auto=0' for the duration of this call to prevent the rebase from
running a potentially slow garbage collection cycle.
Args:
parent - The new parent ref for the rebased commits.
start - The commit to start from
branch - The branch to rebase
abort - If True, will call git-rebase --abort in the event that the rebase
doesn't complete successfully.
allow_gc - If True, sets "-c gc.auto=1" on the rebase call, rather than
"-c gc.auto=0". Usually if you're doing a series of rebases,
you'll only want to run a single gc pass at the end of all the
rebase activity.
Returns a namedtuple with fields:
success - a boolean indicating that the rebase command completed
Expand All @@ -658,10 +665,16 @@ def rebase(parent, start, branch, abort=False):
rebase.
"""
try:
args = ['--onto', parent, start, branch]
args = [
'-c', 'gc.auto={}'.format('1' if allow_gc else '0'),
'rebase',
]
if TEST_MODE:
args.insert(0, '--committer-date-is-author-date')
run('rebase', *args)
args.append('--committer-date-is-author-date')
args += [
'--onto', parent, start, branch,
]
run(*args)
return RebaseRet(True, '', '')
except subprocess2.CalledProcessError as cpe:
if abort:
Expand Down Expand Up @@ -1064,7 +1077,7 @@ def get_branches_info(include_tracking_status):
behind = int(behind_match.group(1)) if behind_match else None

info_map[branch] = BranchesInfo(
hash=branch_hash, upstream=upstream_branch, commits=commits,
hash=branch_hash, upstream=upstream_branch, commits=commits,
behind=behind)

# Set None for upstreams which are not branches (e.g empty upstream, remotes
Expand Down
4 changes: 4 additions & 0 deletions git_rebase_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ def main(args=None):
git.set_config(STARTING_BRANCH_KEY, '')
git.set_config(STARTING_WORKDIR_KEY, '')

print()
print("Running `git gc --auto` - Ctrl-C to abort is OK.")
git.run('gc', '--auto')

return retcode


Expand Down

0 comments on commit d3acb16

Please sign in to comment.