import argparse
import logging
from util import jj_log
from util import run_command
from util import run_jj
def _fetch(shallow: bool) -> None:
args = ['git', 'fetch', 'origin', 'main']
if shallow:
history_limit = jj_log(revisions='parents(fork_point(parents(mutable())))',
templates={'commit_id': 'commit_id'},
ignore_working_copy=True)
assert len(history_limit) == 1
history_limit = history_limit[0]['commit_id']
args.append(f'--shallow-exclude={history_limit}')
run_command(args)
def main(args):
logging.basicConfig(level=logging.getLevelNamesMapping()[args.verbosity])
_fetch(args.shallow)
logging.info('Rebasing onto main@origin')
rebase_source = 'mutable()' if args.all else '@'
run_jj(['rebase', '-b', rebase_source, '-d', 'trunk()', '--skip-emptied'])
run_jj(['simplify-parents', '-r', 'mutable()'], ignore_working_copy=True)
while True:
logging.info('Running gclient sync')
ps = run_command(['gclient', 'sync', '-D'], check=False)
if ps.returncode == 0:
break
else:
input('press control-C to exit, or enter to retry gclient sync')
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(
'--verbosity',
help='Verbosity of logging',
default='INFO',
choices=logging.getLevelNamesMapping().keys(),
type=lambda x: x.upper(),
)
parser.add_argument(
'-a',
'--all',
help='Rebases all local changes onto head',
action='store_true',
)
parser.add_argument(
'-s',
'--shallow',
help=
'Garbage-collects all commits before the common ancestor of all mutable commits',
action='store_true',
)
main(parser.parse_args())