mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
switch to 4 space indent
Leave the recipes/ code at 2 space to match the rest of the recipes
project in other repos.
Reformatted using:
files=( $(
git ls-tree -r --name-only HEAD | \
grep -Ev -e '^(third_party|recipes)/' | \
grep '\.py$';
git grep -l '#!/usr/bin/env.*python' | grep -v '\.py$'
) )
parallel ./yapf -i -- "${files[@]}"
~/chromiumos/chromite/contrib/reflow_overlong_comments "${files[@]}"
The files that still had strings that were too long were manually
reformatted because they were easy and only a few issues.
autoninja.py
clang_format.py
download_from_google_storage.py
fix_encoding.py
gclient_utils.py
git_cache.py
git_common.py
git_map_branches.py
git_reparent_branch.py
gn.py
my_activity.py
owners_finder.py
presubmit_canned_checks.py
reclient_helper.py
reclientreport.py
roll_dep.py
rustfmt.py
siso.py
split_cl.py
subcommand.py
subprocess2.py
swift_format.py
upload_to_google_storage.py
These files still had lines (strings) that were too long, so the pylint
warnings were suppressed with a TODO.
auth.py
gclient.py
gclient_eval.py
gclient_paths.py
gclient_scm.py
gerrit_util.py
git_cl.py
presubmit_canned_checks.py
presubmit_support.py
scm.py
Change-Id: Ia6535c4f2c48d46b589ec1e791dde6c6b2ea858f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4836379
Commit-Queue: Josip Sokcevic <sokcevic@chromium.org>
Auto-Submit: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
This commit is contained in:
@@ -18,105 +18,118 @@ import git_common
|
||||
|
||||
|
||||
def parse_options():
|
||||
if sys.platform == 'win32':
|
||||
print('ERROR: This script cannot run on Windows because it uses symlinks.')
|
||||
sys.exit(1)
|
||||
if sys.platform == 'win32':
|
||||
print(
|
||||
'ERROR: This script cannot run on Windows because it uses symlinks.'
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
parser = argparse.ArgumentParser(description='''\
|
||||
parser = argparse.ArgumentParser(description='''\
|
||||
Clone an existing gclient directory, taking care of all sub-repositories.
|
||||
Works similarly to 'git new-workdir'.''')
|
||||
parser.add_argument('repository', type=os.path.abspath,
|
||||
help='should contain a .gclient file')
|
||||
parser.add_argument('new_workdir', help='must not exist')
|
||||
parser.add_argument('--reflink', action='store_true', default=None,
|
||||
help='''force to use "cp --reflink" for speed and disk
|
||||
parser.add_argument('repository',
|
||||
type=os.path.abspath,
|
||||
help='should contain a .gclient file')
|
||||
parser.add_argument('new_workdir', help='must not exist')
|
||||
parser.add_argument('--reflink',
|
||||
action='store_true',
|
||||
default=None,
|
||||
help='''force to use "cp --reflink" for speed and disk
|
||||
space. need supported FS like btrfs or ZFS.''')
|
||||
parser.add_argument('--no-reflink', action='store_false', dest='reflink',
|
||||
help='''force not to use "cp --reflink" even on supported
|
||||
parser.add_argument(
|
||||
'--no-reflink',
|
||||
action='store_false',
|
||||
dest='reflink',
|
||||
help='''force not to use "cp --reflink" even on supported
|
||||
FS like btrfs or ZFS.''')
|
||||
args = parser.parse_args()
|
||||
args = parser.parse_args()
|
||||
|
||||
if not os.path.exists(args.repository):
|
||||
parser.error('Repository "%s" does not exist.' % args.repository)
|
||||
if not os.path.exists(args.repository):
|
||||
parser.error('Repository "%s" does not exist.' % args.repository)
|
||||
|
||||
gclient = os.path.join(args.repository, '.gclient')
|
||||
if not os.path.exists(gclient):
|
||||
parser.error('No .gclient file at "%s".' % gclient)
|
||||
gclient = os.path.join(args.repository, '.gclient')
|
||||
if not os.path.exists(gclient):
|
||||
parser.error('No .gclient file at "%s".' % gclient)
|
||||
|
||||
if os.path.exists(args.new_workdir):
|
||||
parser.error('New workdir "%s" already exists.' % args.new_workdir)
|
||||
if os.path.exists(args.new_workdir):
|
||||
parser.error('New workdir "%s" already exists.' % args.new_workdir)
|
||||
|
||||
return args
|
||||
return args
|
||||
|
||||
|
||||
def support_cow(src, dest):
|
||||
# 'cp --reflink' always succeeds when 'src' is a symlink or a directory
|
||||
assert os.path.isfile(src) and not os.path.islink(src)
|
||||
try:
|
||||
subprocess.check_output(['cp', '-a', '--reflink', src, dest],
|
||||
stderr=subprocess.STDOUT)
|
||||
except subprocess.CalledProcessError:
|
||||
return False
|
||||
finally:
|
||||
if os.path.isfile(dest):
|
||||
os.remove(dest)
|
||||
return True
|
||||
# 'cp --reflink' always succeeds when 'src' is a symlink or a directory
|
||||
assert os.path.isfile(src) and not os.path.islink(src)
|
||||
try:
|
||||
subprocess.check_output(['cp', '-a', '--reflink', src, dest],
|
||||
stderr=subprocess.STDOUT)
|
||||
except subprocess.CalledProcessError:
|
||||
return False
|
||||
finally:
|
||||
if os.path.isfile(dest):
|
||||
os.remove(dest)
|
||||
return True
|
||||
|
||||
|
||||
def try_vol_snapshot(src, dest):
|
||||
try:
|
||||
subprocess.check_call(['btrfs', 'subvol', 'snapshot', src, dest],
|
||||
stderr=subprocess.STDOUT)
|
||||
except (subprocess.CalledProcessError, OSError):
|
||||
return False
|
||||
return True
|
||||
try:
|
||||
subprocess.check_call(['btrfs', 'subvol', 'snapshot', src, dest],
|
||||
stderr=subprocess.STDOUT)
|
||||
except (subprocess.CalledProcessError, OSError):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def main():
|
||||
args = parse_options()
|
||||
args = parse_options()
|
||||
|
||||
gclient = os.path.join(args.repository, '.gclient')
|
||||
if os.path.islink(gclient):
|
||||
gclient = os.path.realpath(gclient)
|
||||
new_gclient = os.path.join(args.new_workdir, '.gclient')
|
||||
gclient = os.path.join(args.repository, '.gclient')
|
||||
if os.path.islink(gclient):
|
||||
gclient = os.path.realpath(gclient)
|
||||
new_gclient = os.path.join(args.new_workdir, '.gclient')
|
||||
|
||||
if try_vol_snapshot(args.repository, args.new_workdir):
|
||||
args.reflink = True
|
||||
else:
|
||||
os.makedirs(args.new_workdir)
|
||||
if args.reflink is None:
|
||||
args.reflink = support_cow(gclient, new_gclient)
|
||||
if args.reflink:
|
||||
print('Copy-on-write support is detected.')
|
||||
os.symlink(gclient, new_gclient)
|
||||
if try_vol_snapshot(args.repository, args.new_workdir):
|
||||
args.reflink = True
|
||||
else:
|
||||
os.makedirs(args.new_workdir)
|
||||
if args.reflink is None:
|
||||
args.reflink = support_cow(gclient, new_gclient)
|
||||
if args.reflink:
|
||||
print('Copy-on-write support is detected.')
|
||||
os.symlink(gclient, new_gclient)
|
||||
|
||||
for root, dirs, _ in os.walk(args.repository):
|
||||
if '.git' in dirs:
|
||||
workdir = root.replace(args.repository, args.new_workdir, 1)
|
||||
print('Creating: %s' % workdir)
|
||||
for root, dirs, _ in os.walk(args.repository):
|
||||
if '.git' in dirs:
|
||||
workdir = root.replace(args.repository, args.new_workdir, 1)
|
||||
print('Creating: %s' % workdir)
|
||||
|
||||
if args.reflink:
|
||||
if not os.path.exists(workdir):
|
||||
print('Copying: %s' % workdir)
|
||||
subprocess.check_call(['cp', '-a', '--reflink', root, workdir])
|
||||
shutil.rmtree(os.path.join(workdir, '.git'))
|
||||
if args.reflink:
|
||||
if not os.path.exists(workdir):
|
||||
print('Copying: %s' % workdir)
|
||||
subprocess.check_call(
|
||||
['cp', '-a', '--reflink', root, workdir])
|
||||
shutil.rmtree(os.path.join(workdir, '.git'))
|
||||
|
||||
git_common.make_workdir(os.path.join(root, '.git'),
|
||||
os.path.join(workdir, '.git'))
|
||||
if args.reflink:
|
||||
subprocess.check_call(['cp', '-a', '--reflink',
|
||||
os.path.join(root, '.git', 'index'),
|
||||
os.path.join(workdir, '.git', 'index')])
|
||||
else:
|
||||
subprocess.check_call(['git', 'checkout', '-f'], cwd=workdir)
|
||||
git_common.make_workdir(os.path.join(root, '.git'),
|
||||
os.path.join(workdir, '.git'))
|
||||
if args.reflink:
|
||||
subprocess.check_call([
|
||||
'cp', '-a', '--reflink',
|
||||
os.path.join(root, '.git', 'index'),
|
||||
os.path.join(workdir, '.git', 'index')
|
||||
])
|
||||
else:
|
||||
subprocess.check_call(['git', 'checkout', '-f'], cwd=workdir)
|
||||
|
||||
if args.reflink:
|
||||
print(textwrap.dedent('''\
|
||||
if args.reflink:
|
||||
print(
|
||||
textwrap.dedent('''\
|
||||
The repo was copied with copy-on-write, and the artifacts were retained.
|
||||
More details on http://crbug.com/721585.
|
||||
|
||||
Depending on your usage pattern, you might want to do "gn gen"
|
||||
on the output directories. More details: http://crbug.com/723856.'''))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
sys.exit(main())
|
||||
|
||||
Reference in New Issue
Block a user