2016-11-07 21:00:47 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# ======- git-llvm - LLVM Git Help Integration ---------*- python -*--========#
|
|
|
|
#
|
2019-01-19 09:50:56 +01:00
|
|
|
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
# See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2016-11-07 21:00:47 +01:00
|
|
|
#
|
|
|
|
# ==------------------------------------------------------------------------==#
|
|
|
|
|
|
|
|
"""
|
|
|
|
git-llvm integration
|
|
|
|
====================
|
|
|
|
|
|
|
|
This file provides integration for git.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
import argparse
|
|
|
|
import collections
|
|
|
|
import os
|
|
|
|
import re
|
2019-03-12 08:40:54 +01:00
|
|
|
import shutil
|
2016-11-07 21:00:47 +01:00
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
assert sys.version_info >= (2, 7)
|
|
|
|
|
2018-11-17 00:59:23 +01:00
|
|
|
try:
|
|
|
|
dict.iteritems
|
|
|
|
except AttributeError:
|
|
|
|
# Python 3
|
|
|
|
def iteritems(d):
|
|
|
|
return iter(d.items())
|
|
|
|
else:
|
|
|
|
# Python 2
|
|
|
|
def iteritems(d):
|
|
|
|
return d.iteritems()
|
2016-11-07 21:00:47 +01:00
|
|
|
|
2019-03-28 17:15:28 +01:00
|
|
|
try:
|
|
|
|
# Python 3
|
|
|
|
from shlex import quote
|
|
|
|
except ImportError:
|
|
|
|
# Python 2
|
|
|
|
from pipes import quote
|
|
|
|
|
2016-11-07 21:00:47 +01:00
|
|
|
# It's *almost* a straightforward mapping from the monorepo to svn...
|
2019-07-12 18:40:46 +02:00
|
|
|
LLVM_MONOREPO_SVN_MAPPING = {
|
2016-11-07 21:00:47 +01:00
|
|
|
d: (d + '/trunk')
|
|
|
|
for d in [
|
|
|
|
'clang-tools-extra',
|
|
|
|
'compiler-rt',
|
2017-06-05 00:18:57 +02:00
|
|
|
'debuginfo-tests',
|
2016-11-07 21:00:47 +01:00
|
|
|
'dragonegg',
|
|
|
|
'klee',
|
2019-09-17 01:36:35 +02:00
|
|
|
'libc',
|
2016-11-07 21:00:47 +01:00
|
|
|
'libclc',
|
|
|
|
'libcxx',
|
|
|
|
'libcxxabi',
|
2017-06-05 00:18:57 +02:00
|
|
|
'libunwind',
|
2016-11-07 21:00:47 +01:00
|
|
|
'lld',
|
|
|
|
'lldb',
|
2017-06-05 00:18:57 +02:00
|
|
|
'llgo',
|
2016-11-07 21:00:47 +01:00
|
|
|
'llvm',
|
2017-06-05 00:18:57 +02:00
|
|
|
'openmp',
|
|
|
|
'parallel-libs',
|
2016-11-07 21:00:47 +01:00
|
|
|
'polly',
|
2018-11-16 23:36:17 +01:00
|
|
|
'pstl',
|
2016-11-07 21:00:47 +01:00
|
|
|
]
|
|
|
|
}
|
2019-07-12 18:40:46 +02:00
|
|
|
LLVM_MONOREPO_SVN_MAPPING.update({'clang': 'cfe/trunk'})
|
|
|
|
LLVM_MONOREPO_SVN_MAPPING.update({'': 'monorepo-root/trunk'})
|
|
|
|
|
2019-07-12 18:41:28 +02:00
|
|
|
SPLIT_REPO_NAMES = {'llvm-' + d: d + '/trunk'
|
2019-07-12 18:40:46 +02:00
|
|
|
for d in ['www', 'zorg', 'test-suite', 'lnt']}
|
2016-11-07 21:00:47 +01:00
|
|
|
|
|
|
|
VERBOSE = False
|
|
|
|
QUIET = False
|
2017-04-25 00:09:08 +02:00
|
|
|
dev_null_fd = None
|
2016-11-07 21:00:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
def eprint(*args, **kwargs):
|
|
|
|
print(*args, file=sys.stderr, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
def log(*args, **kwargs):
|
|
|
|
if QUIET:
|
|
|
|
return
|
|
|
|
print(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
def log_verbose(*args, **kwargs):
|
|
|
|
if not VERBOSE:
|
|
|
|
return
|
|
|
|
print(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
def die(msg):
|
|
|
|
eprint(msg)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
2019-07-30 17:25:14 +02:00
|
|
|
def ask_confirm(prompt):
|
|
|
|
# Python 2/3 compatibility
|
|
|
|
try:
|
2019-08-03 20:53:52 +02:00
|
|
|
read_input = raw_input
|
2019-07-30 17:25:14 +02:00
|
|
|
except NameError:
|
2019-08-03 20:53:52 +02:00
|
|
|
read_input = input
|
2019-07-30 17:25:14 +02:00
|
|
|
|
|
|
|
while True:
|
2019-08-03 20:53:52 +02:00
|
|
|
query = read_input('%s (y/N): ' % (prompt))
|
2019-07-30 17:25:14 +02:00
|
|
|
if query.lower() not in ['y','n', '']:
|
|
|
|
print('Expect y or n!')
|
|
|
|
continue
|
|
|
|
return query.lower() == 'y'
|
|
|
|
|
|
|
|
|
2018-11-16 23:36:17 +01:00
|
|
|
def split_first_path_component(d):
|
|
|
|
# Assuming we have a git path, it'll use slashes even on windows...I hope.
|
|
|
|
if '/' in d:
|
|
|
|
return d.split('/', 1)
|
|
|
|
else:
|
|
|
|
return (d, None)
|
2016-11-07 21:00:47 +01:00
|
|
|
|
|
|
|
|
2017-04-25 00:09:08 +02:00
|
|
|
def get_dev_null():
|
|
|
|
"""Lazily create a /dev/null fd for use in shell()"""
|
|
|
|
global dev_null_fd
|
|
|
|
if dev_null_fd is None:
|
|
|
|
dev_null_fd = open(os.devnull, 'w')
|
|
|
|
return dev_null_fd
|
|
|
|
|
|
|
|
|
|
|
|
def shell(cmd, strip=True, cwd=None, stdin=None, die_on_failure=True,
|
2018-11-28 16:30:39 +01:00
|
|
|
ignore_errors=False, text=True):
|
2019-03-28 17:15:28 +01:00
|
|
|
# Escape args when logging for easy repro.
|
|
|
|
quoted_cmd = [quote(arg) for arg in cmd]
|
|
|
|
log_verbose('Running in %s: %s' % (cwd, ' '.join(quoted_cmd)))
|
2016-11-07 21:00:47 +01:00
|
|
|
|
2017-04-25 00:09:08 +02:00
|
|
|
err_pipe = subprocess.PIPE
|
|
|
|
if ignore_errors:
|
|
|
|
# Silence errors if requested.
|
|
|
|
err_pipe = get_dev_null()
|
|
|
|
|
2016-11-07 21:00:47 +01:00
|
|
|
start = time.time()
|
2017-04-25 00:09:08 +02:00
|
|
|
p = subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=err_pipe,
|
2018-11-28 16:30:39 +01:00
|
|
|
stdin=subprocess.PIPE,
|
|
|
|
universal_newlines=text)
|
2016-11-07 21:00:47 +01:00
|
|
|
stdout, stderr = p.communicate(input=stdin)
|
|
|
|
elapsed = time.time() - start
|
|
|
|
|
|
|
|
log_verbose('Command took %0.1fs' % elapsed)
|
|
|
|
|
2017-04-25 00:09:08 +02:00
|
|
|
if p.returncode == 0 or ignore_errors:
|
|
|
|
if stderr and not ignore_errors:
|
2019-03-28 17:15:28 +01:00
|
|
|
eprint('`%s` printed to stderr:' % ' '.join(quoted_cmd))
|
2016-11-07 21:00:47 +01:00
|
|
|
eprint(stderr.rstrip())
|
|
|
|
if strip:
|
2018-11-28 16:30:39 +01:00
|
|
|
if text:
|
|
|
|
stdout = stdout.rstrip('\r\n')
|
|
|
|
else:
|
|
|
|
stdout = stdout.rstrip(b'\r\n')
|
2018-11-16 23:36:17 +01:00
|
|
|
if VERBOSE:
|
|
|
|
for l in stdout.splitlines():
|
|
|
|
log_verbose("STDOUT: %s" % l)
|
2016-11-07 21:00:47 +01:00
|
|
|
return stdout
|
2019-03-28 17:15:28 +01:00
|
|
|
err_msg = '`%s` returned %s' % (' '.join(quoted_cmd), p.returncode)
|
2016-11-12 02:17:59 +01:00
|
|
|
eprint(err_msg)
|
2016-11-07 21:00:47 +01:00
|
|
|
if stderr:
|
|
|
|
eprint(stderr.rstrip())
|
2016-11-12 02:17:59 +01:00
|
|
|
if die_on_failure:
|
|
|
|
sys.exit(2)
|
|
|
|
raise RuntimeError(err_msg)
|
2016-11-07 21:00:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
def git(*cmd, **kwargs):
|
2018-11-28 16:30:39 +01:00
|
|
|
return shell(['git'] + list(cmd), **kwargs)
|
2016-11-07 21:00:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
def svn(cwd, *cmd, **kwargs):
|
2018-11-28 16:30:39 +01:00
|
|
|
return shell(['svn'] + list(cmd), cwd=cwd, **kwargs)
|
2016-11-07 21:00:47 +01:00
|
|
|
|
2019-07-12 18:41:28 +02:00
|
|
|
|
2017-05-23 23:50:40 +02:00
|
|
|
def program_exists(cmd):
|
2017-05-24 02:28:46 +02:00
|
|
|
if sys.platform == 'win32' and not cmd.endswith('.exe'):
|
|
|
|
cmd += '.exe'
|
2017-05-23 23:50:40 +02:00
|
|
|
for path in os.environ["PATH"].split(os.pathsep):
|
|
|
|
if os.access(os.path.join(path, cmd), os.X_OK):
|
|
|
|
return True
|
|
|
|
return False
|
2016-11-07 21:00:47 +01:00
|
|
|
|
2019-07-12 18:41:28 +02:00
|
|
|
|
2016-11-07 21:00:47 +01:00
|
|
|
def get_default_rev_range():
|
|
|
|
# Get the newest common ancestor between HEAD and our upstream branch.
|
2019-09-17 06:44:13 +02:00
|
|
|
upstream_rev = git('merge-base', 'HEAD', '@{upstream}', ignore_errors=True)
|
|
|
|
if not upstream_rev:
|
|
|
|
eprint("Warning: git-llvm assumes that origin/master is the upstream "
|
|
|
|
"branch but git does not.")
|
|
|
|
eprint("To make this warning go away: git branch -u origin/master")
|
|
|
|
eprint("To avoid this warning when creating branches: "
|
|
|
|
"git checkout -b MyBranchName origin/master")
|
|
|
|
upstream_rev = git('merge-base', 'HEAD', 'origin/master')
|
|
|
|
|
2016-11-07 21:00:47 +01:00
|
|
|
return '%s..' % upstream_rev
|
|
|
|
|
|
|
|
|
|
|
|
def get_revs_to_push(rev_range):
|
|
|
|
if not rev_range:
|
|
|
|
rev_range = get_default_rev_range()
|
|
|
|
# Use git show rather than some plumbing command to figure out which revs
|
|
|
|
# are in rev_range because it handles single revs (HEAD^) and ranges
|
|
|
|
# (foo..bar) like we want.
|
2019-08-21 18:03:34 +02:00
|
|
|
return git('show', '--reverse', '--quiet',
|
2016-11-07 21:00:47 +01:00
|
|
|
'--pretty=%h', rev_range).splitlines()
|
|
|
|
|
|
|
|
|
2018-11-16 23:36:17 +01:00
|
|
|
def clean_svn(svn_repo):
|
2016-11-07 21:00:47 +01:00
|
|
|
svn(svn_repo, 'revert', '-R', '.')
|
|
|
|
|
|
|
|
# Unfortunately it appears there's no svn equivalent for git clean, so we
|
|
|
|
# have to do it ourselves.
|
2017-12-22 22:19:13 +01:00
|
|
|
for line in svn(svn_repo, 'status', '--no-ignore').split('\n'):
|
2016-11-07 21:00:47 +01:00
|
|
|
if not line.startswith('?'):
|
|
|
|
continue
|
|
|
|
filename = line[1:].strip()
|
2019-03-12 08:40:54 +01:00
|
|
|
filepath = os.path.abspath(os.path.join(svn_repo, filename))
|
|
|
|
abs_svn_repo = os.path.abspath(svn_repo)
|
|
|
|
# Safety check that the directory we are about to delete is
|
|
|
|
# actually within our svn staging dir.
|
|
|
|
if not filepath.startswith(abs_svn_repo):
|
|
|
|
die("Path to clean (%s) is not in svn staging dir (%s)"
|
|
|
|
% (filepath, abs_svn_repo))
|
|
|
|
|
|
|
|
if os.path.isdir(filepath):
|
|
|
|
shutil.rmtree(filepath)
|
|
|
|
else:
|
|
|
|
os.remove(filepath)
|
2016-11-07 21:00:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
def svn_init(svn_root):
|
|
|
|
if not os.path.exists(svn_root):
|
|
|
|
log('Creating svn staging directory: (%s)' % (svn_root))
|
|
|
|
os.makedirs(svn_root)
|
2018-11-28 16:30:39 +01:00
|
|
|
svn(svn_root, 'checkout', '--depth=empty',
|
2016-11-07 21:00:47 +01:00
|
|
|
'https://llvm.org/svn/llvm-project/', '.')
|
|
|
|
log("svn staging area ready in '%s'" % svn_root)
|
|
|
|
if not os.path.isdir(svn_root):
|
|
|
|
die("Can't initialize svn staging dir (%s)" % svn_root)
|
|
|
|
|
|
|
|
|
2018-11-16 23:36:17 +01:00
|
|
|
def fix_eol_style_native(rev, svn_sr_path, files):
|
2017-04-25 00:09:08 +02:00
|
|
|
"""Fix line endings before applying patches with Unix endings
|
|
|
|
|
|
|
|
SVN on Windows will check out files with CRLF for files with the
|
|
|
|
svn:eol-style property set to "native". This breaks `git apply`, which
|
|
|
|
typically works with Unix-line ending patches. Work around the problem here
|
|
|
|
by doing a dos2unix up front for files with svn:eol-style set to "native".
|
|
|
|
SVN will not commit a mass line ending re-doing because it detects the line
|
|
|
|
ending format for files with this property.
|
|
|
|
"""
|
2017-05-18 19:17:17 +02:00
|
|
|
# Skip files that don't exist in SVN yet.
|
|
|
|
files = [f for f in files if os.path.exists(os.path.join(svn_sr_path, f))]
|
2017-04-25 00:09:08 +02:00
|
|
|
# Use ignore_errors because 'svn propget' prints errors if the file doesn't
|
|
|
|
# have the named property. There doesn't seem to be a way to suppress that.
|
|
|
|
eol_props = svn(svn_sr_path, 'propget', 'svn:eol-style', *files,
|
2017-05-12 02:10:19 +02:00
|
|
|
ignore_errors=True)
|
2017-04-25 00:09:08 +02:00
|
|
|
crlf_files = []
|
2017-05-12 02:10:19 +02:00
|
|
|
if len(files) == 1:
|
|
|
|
# No need to split propget output on ' - ' when we have one file.
|
2018-10-10 01:42:28 +02:00
|
|
|
if eol_props.strip() in ['native', 'CRLF']:
|
2017-05-12 02:10:19 +02:00
|
|
|
crlf_files = files
|
|
|
|
else:
|
|
|
|
for eol_prop in eol_props.split('\n'):
|
|
|
|
# Remove spare CR.
|
|
|
|
eol_prop = eol_prop.strip('\r')
|
|
|
|
if not eol_prop:
|
|
|
|
continue
|
|
|
|
prop_parts = eol_prop.rsplit(' - ', 1)
|
|
|
|
if len(prop_parts) != 2:
|
|
|
|
eprint("unable to parse svn propget line:")
|
|
|
|
eprint(eol_prop)
|
|
|
|
continue
|
|
|
|
(f, eol_style) = prop_parts
|
|
|
|
if eol_style == 'native':
|
|
|
|
crlf_files.append(f)
|
2018-10-10 01:42:28 +02:00
|
|
|
if crlf_files:
|
2018-11-16 23:36:17 +01:00
|
|
|
# Reformat all files with native SVN line endings to Unix format. SVN
|
|
|
|
# knows files with native line endings are text files. It will commit
|
|
|
|
# just the diff, and not a mass line ending change.
|
2018-10-10 01:42:28 +02:00
|
|
|
shell(['dos2unix'] + crlf_files, ignore_errors=True, cwd=svn_sr_path)
|
2017-04-25 00:09:08 +02:00
|
|
|
|
2019-07-12 18:41:28 +02:00
|
|
|
|
2019-07-12 18:40:46 +02:00
|
|
|
def split_subrepo(f, git_to_svn_mapping):
|
2018-11-16 23:36:17 +01:00
|
|
|
# Given a path, splits it into (subproject, rest-of-path). If the path is
|
|
|
|
# not in a subproject, returns ('', full-path).
|
|
|
|
|
|
|
|
subproject, remainder = split_first_path_component(f)
|
|
|
|
|
2019-07-12 18:40:46 +02:00
|
|
|
if subproject in git_to_svn_mapping:
|
2018-11-16 23:36:17 +01:00
|
|
|
return subproject, remainder
|
|
|
|
else:
|
|
|
|
return '', f
|
|
|
|
|
2019-07-12 18:41:28 +02:00
|
|
|
|
git-llvm: Fix incremental population of svn tree.
"svn update --depth=..." is, annoyingly, not a specification of the
desired depth, but rather a _limit_ added on top of the "sticky" depth
in the working-directory. However, if the directory doesn't exist yet,
then it sets the sticky depth of the new directory entries.
Unfortunately, the svn command-line has no way of expanding the depth
of a directory from "empty" to "files", without also removing any
already-expanded subdirectories. The way you're supposed to increase
the depth of an existing directory is via --set-depth, but
--set-depth=files will also remove any subdirs which were already
requested.
This change avoids getting into the state of ever needing to increase
the depth of an existing directory from "empty" to "files" in the
first place, by:
1. Use svn update --depth=files, not --depth=immediates.
The latter has the effect of checking out the subdirectories and
marking them as depth=empty. The former excludes sub-directories from
the list of entries, which avoids the problem.
2. Explicitly populate missing parent directories.
Using --parents seemed nice and easy, but it marks the parent dirs as
depth=empty. Instead, check out parents explicitly if they're missing.
llvm-svn: 347883
2018-11-29 17:46:34 +01:00
|
|
|
def get_all_parent_dirs(name):
|
|
|
|
parts = []
|
|
|
|
head, tail = os.path.split(name)
|
|
|
|
while head:
|
|
|
|
parts.append(head)
|
|
|
|
head, tail = os.path.split(head)
|
|
|
|
return parts
|
|
|
|
|
2019-07-12 18:41:28 +02:00
|
|
|
|
2019-07-12 18:40:46 +02:00
|
|
|
def svn_push_one_rev(svn_repo, rev, git_to_svn_mapping, dry_run):
|
2019-08-02 19:10:04 +02:00
|
|
|
def split_status(x):
|
|
|
|
x = x.split('\t')
|
|
|
|
return x[1], x[0]
|
|
|
|
files_status = [split_status(x) for x in
|
|
|
|
git('diff-tree', '--no-commit-id', '--name-status',
|
|
|
|
'--no-renames', '-r', rev).split('\n')]
|
|
|
|
if not files_status:
|
2016-11-07 21:00:47 +01:00
|
|
|
raise RuntimeError('Empty diff for rev %s?' % rev)
|
|
|
|
|
2018-11-16 23:36:17 +01:00
|
|
|
# Split files by subrepo
|
|
|
|
subrepo_files = collections.defaultdict(list)
|
2019-08-02 19:10:04 +02:00
|
|
|
for f, st in files_status:
|
2019-07-12 18:40:46 +02:00
|
|
|
subrepo, remainder = split_subrepo(f, git_to_svn_mapping)
|
2019-08-02 19:10:04 +02:00
|
|
|
subrepo_files[subrepo].append((remainder, st))
|
2018-11-16 23:36:17 +01:00
|
|
|
|
2017-12-22 22:19:13 +01:00
|
|
|
status = svn(svn_repo, 'status', '--no-ignore')
|
2016-11-07 21:00:47 +01:00
|
|
|
if status:
|
2019-07-22 11:47:40 +02:00
|
|
|
die("Can't push git rev %s because status in svn staging dir (%s) is "
|
|
|
|
"not empty:\n%s" % (rev, svn_repo, status))
|
2016-11-07 21:00:47 +01:00
|
|
|
|
2018-11-16 23:36:17 +01:00
|
|
|
svn_dirs_to_update = set()
|
2019-08-02 19:10:04 +02:00
|
|
|
for sr, files_status in iteritems(subrepo_files):
|
2019-07-12 18:40:46 +02:00
|
|
|
svn_sr_path = git_to_svn_mapping[sr]
|
2019-08-02 19:10:04 +02:00
|
|
|
for f, _ in files_status:
|
2018-11-28 16:30:39 +01:00
|
|
|
svn_dirs_to_update.add(
|
|
|
|
os.path.dirname(os.path.join(svn_sr_path, f)))
|
2018-11-16 23:36:17 +01:00
|
|
|
|
2019-07-12 18:41:28 +02:00
|
|
|
# We also need to svn update any parent directories which are not yet
|
|
|
|
# present
|
git-llvm: Fix incremental population of svn tree.
"svn update --depth=..." is, annoyingly, not a specification of the
desired depth, but rather a _limit_ added on top of the "sticky" depth
in the working-directory. However, if the directory doesn't exist yet,
then it sets the sticky depth of the new directory entries.
Unfortunately, the svn command-line has no way of expanding the depth
of a directory from "empty" to "files", without also removing any
already-expanded subdirectories. The way you're supposed to increase
the depth of an existing directory is via --set-depth, but
--set-depth=files will also remove any subdirs which were already
requested.
This change avoids getting into the state of ever needing to increase
the depth of an existing directory from "empty" to "files" in the
first place, by:
1. Use svn update --depth=files, not --depth=immediates.
The latter has the effect of checking out the subdirectories and
marking them as depth=empty. The former excludes sub-directories from
the list of entries, which avoids the problem.
2. Explicitly populate missing parent directories.
Using --parents seemed nice and easy, but it marks the parent dirs as
depth=empty. Instead, check out parents explicitly if they're missing.
llvm-svn: 347883
2018-11-29 17:46:34 +01:00
|
|
|
parent_dirs = set()
|
|
|
|
for dir in svn_dirs_to_update:
|
|
|
|
parent_dirs.update(get_all_parent_dirs(dir))
|
|
|
|
parent_dirs = set(dir for dir in parent_dirs
|
|
|
|
if not os.path.exists(os.path.join(svn_repo, dir)))
|
|
|
|
svn_dirs_to_update.update(parent_dirs)
|
|
|
|
|
|
|
|
# Sort by length to ensure that the parent directories are passed to svn
|
|
|
|
# before child directories.
|
|
|
|
sorted_dirs_to_update = sorted(svn_dirs_to_update, key=len)
|
|
|
|
|
2018-11-16 23:36:17 +01:00
|
|
|
# SVN update only in the affected directories.
|
git-llvm: Fix incremental population of svn tree.
"svn update --depth=..." is, annoyingly, not a specification of the
desired depth, but rather a _limit_ added on top of the "sticky" depth
in the working-directory. However, if the directory doesn't exist yet,
then it sets the sticky depth of the new directory entries.
Unfortunately, the svn command-line has no way of expanding the depth
of a directory from "empty" to "files", without also removing any
already-expanded subdirectories. The way you're supposed to increase
the depth of an existing directory is via --set-depth, but
--set-depth=files will also remove any subdirs which were already
requested.
This change avoids getting into the state of ever needing to increase
the depth of an existing directory from "empty" to "files" in the
first place, by:
1. Use svn update --depth=files, not --depth=immediates.
The latter has the effect of checking out the subdirectories and
marking them as depth=empty. The former excludes sub-directories from
the list of entries, which avoids the problem.
2. Explicitly populate missing parent directories.
Using --parents seemed nice and easy, but it marks the parent dirs as
depth=empty. Instead, check out parents explicitly if they're missing.
llvm-svn: 347883
2018-11-29 17:46:34 +01:00
|
|
|
svn(svn_repo, 'update', '--depth=files', *sorted_dirs_to_update)
|
2018-11-16 23:36:17 +01:00
|
|
|
|
2019-08-02 19:10:04 +02:00
|
|
|
for sr, files_status in iteritems(subrepo_files):
|
2019-07-12 18:40:46 +02:00
|
|
|
svn_sr_path = os.path.join(svn_repo, git_to_svn_mapping[sr])
|
2017-04-25 00:09:08 +02:00
|
|
|
if os.name == 'nt':
|
2019-08-02 19:10:04 +02:00
|
|
|
fix_eol_style_native(rev, svn_sr_path,
|
|
|
|
[f for f, _ in files_status])
|
|
|
|
|
2018-11-28 16:30:39 +01:00
|
|
|
# We use text=False (and pass '--binary') so that we can get an exact
|
|
|
|
# diff that can be passed as-is to 'git apply' without any line ending,
|
|
|
|
# encoding, or other mangling.
|
2018-11-16 23:36:17 +01:00
|
|
|
diff = git('show', '--binary', rev, '--',
|
2019-08-02 19:10:04 +02:00
|
|
|
*(os.path.join(sr, f) for f, _ in files_status),
|
2018-11-28 16:30:39 +01:00
|
|
|
strip=False, text=False)
|
2016-11-07 21:00:47 +01:00
|
|
|
# git is the only thing that can handle its own patches...
|
2018-11-16 23:36:17 +01:00
|
|
|
if sr == '':
|
|
|
|
prefix_strip = '-p1'
|
|
|
|
else:
|
|
|
|
prefix_strip = '-p2'
|
2016-11-12 02:17:59 +01:00
|
|
|
try:
|
2018-11-16 23:36:17 +01:00
|
|
|
shell(['git', 'apply', prefix_strip, '-'], cwd=svn_sr_path,
|
2018-11-28 16:30:39 +01:00
|
|
|
stdin=diff, die_on_failure=False, text=False)
|
2016-11-12 02:17:59 +01:00
|
|
|
except RuntimeError as e:
|
|
|
|
eprint("Patch doesn't apply: maybe you should try `git pull -r` "
|
|
|
|
"first?")
|
|
|
|
sys.exit(2)
|
2016-11-07 21:00:47 +01:00
|
|
|
|
2019-08-02 19:10:04 +02:00
|
|
|
# Handle removed files and directories. We need to be careful not to
|
|
|
|
# remove directories just because they _look_ empty in the svn tree, as
|
|
|
|
# we might be missing sibling directories in the working copy. So, only
|
|
|
|
# remove parent directories if they're empty on both the git and svn
|
|
|
|
# sides.
|
|
|
|
maybe_dirs_to_remove = set()
|
|
|
|
for f, st in files_status:
|
|
|
|
if st == 'D':
|
|
|
|
maybe_dirs_to_remove.update(get_all_parent_dirs(f))
|
|
|
|
svn(svn_sr_path, 'remove', f)
|
|
|
|
elif not (st == 'A' or st == 'M' or st == 'T'):
|
|
|
|
# Add is handled below, and nothing needs to be done for Modify.
|
|
|
|
# (FIXME: Type-change between symlink and file might need some
|
|
|
|
# special handling, but let's ignore that for now.)
|
|
|
|
die("Unexpected git status for %r: %r" % (f, st))
|
|
|
|
|
|
|
|
maybe_dirs_to_remove = sorted(maybe_dirs_to_remove, key=len)
|
|
|
|
for f in maybe_dirs_to_remove:
|
|
|
|
if(not os.path.exists(os.path.join(svn_sr_path, f)) and
|
|
|
|
git('ls-tree', '-d', rev, os.path.join(sr, f)) == ''):
|
|
|
|
svn(svn_sr_path, 'remove', f)
|
|
|
|
|
2017-12-22 22:19:13 +01:00
|
|
|
status_lines = svn(svn_repo, 'status', '--no-ignore').split('\n')
|
2016-11-07 21:00:47 +01:00
|
|
|
|
2019-08-02 19:10:04 +02:00
|
|
|
for l in status_lines:
|
|
|
|
f = l[1:].strip()
|
|
|
|
if l.startswith('?') or l.startswith('I'):
|
|
|
|
svn(svn_repo, 'add', '--no-ignore', f)
|
2016-11-07 21:00:47 +01:00
|
|
|
|
|
|
|
# Now we're ready to commit.
|
|
|
|
commit_msg = git('show', '--pretty=%B', '--quiet', rev)
|
|
|
|
if not dry_run:
|
2019-07-16 12:14:53 +02:00
|
|
|
commit_args = ['commit', '-m', commit_msg]
|
2019-03-10 02:34:42 +01:00
|
|
|
if '--force-interactive' in svn(svn_repo, 'commit', '--help'):
|
|
|
|
commit_args.append('--force-interactive')
|
|
|
|
log(svn(svn_repo, *commit_args))
|
2016-11-07 21:00:47 +01:00
|
|
|
log('Committed %s to svn.' % rev)
|
|
|
|
else:
|
|
|
|
log("Would have committed %s to svn, if this weren't a dry run." % rev)
|
|
|
|
|
|
|
|
|
|
|
|
def cmd_push(args):
|
|
|
|
'''Push changes back to SVN: this is extracted from Justin Lebar's script
|
|
|
|
available here: https://github.com/jlebar/llvm-repo-tools/
|
|
|
|
|
|
|
|
Note: a current limitation is that git does not track file rename, so they
|
|
|
|
will show up in SVN as delete+add.
|
|
|
|
'''
|
|
|
|
# Get the git root
|
|
|
|
git_root = git('rev-parse', '--show-toplevel')
|
|
|
|
if not os.path.isdir(git_root):
|
|
|
|
die("Can't find git root dir")
|
|
|
|
|
|
|
|
# Push from the root of the git repo
|
|
|
|
os.chdir(git_root)
|
|
|
|
|
2019-07-12 18:40:46 +02:00
|
|
|
# Get the remote URL, and check if it's one of the standalone repos.
|
2019-07-29 23:01:11 +02:00
|
|
|
git_remote_url = git('ls-remote', '--get-url', 'origin')
|
2019-07-12 18:40:46 +02:00
|
|
|
git_remote_url = git_remote_url.rstrip('.git').rstrip('/')
|
|
|
|
git_remote_repo_name = git_remote_url.rsplit('/', 1)[-1]
|
|
|
|
split_repo_path = SPLIT_REPO_NAMES.get(git_remote_repo_name)
|
|
|
|
if split_repo_path:
|
2019-07-12 18:41:28 +02:00
|
|
|
git_to_svn_mapping = {'': split_repo_path}
|
2019-07-12 18:40:46 +02:00
|
|
|
else:
|
2019-07-12 18:41:28 +02:00
|
|
|
# Default to the monorepo mapping
|
|
|
|
git_to_svn_mapping = LLVM_MONOREPO_SVN_MAPPING
|
2019-07-12 18:40:46 +02:00
|
|
|
|
2016-11-07 21:00:47 +01:00
|
|
|
# We need a staging area for SVN, let's hide it in the .git directory.
|
2016-11-07 21:35:02 +01:00
|
|
|
dot_git_dir = git('rev-parse', '--git-common-dir')
|
2019-05-04 00:03:29 +02:00
|
|
|
# Not all versions of git support --git-common-dir and just print the
|
|
|
|
# unknown command back. If this happens, fall back to --git-dir
|
|
|
|
if dot_git_dir == '--git-common-dir':
|
2019-07-12 18:41:28 +02:00
|
|
|
dot_git_dir = git('rev-parse', '--git-dir')
|
2019-05-04 00:03:29 +02:00
|
|
|
|
2016-11-07 21:35:02 +01:00
|
|
|
svn_root = os.path.join(dot_git_dir, 'llvm-upstream-svn')
|
2016-11-07 21:00:47 +01:00
|
|
|
svn_init(svn_root)
|
|
|
|
|
|
|
|
rev_range = args.rev_range
|
|
|
|
dry_run = args.dry_run
|
|
|
|
revs = get_revs_to_push(rev_range)
|
2019-08-21 18:03:34 +02:00
|
|
|
|
|
|
|
if not args.force and not revs:
|
|
|
|
die('Nothing to push: No revs in range %s.' % rev_range)
|
|
|
|
|
2019-07-14 20:24:19 +02:00
|
|
|
log('%sPushing %d %s commit%s:\n%s' %
|
|
|
|
('[DryRun] ' if dry_run else '', len(revs),
|
2019-07-12 18:41:28 +02:00
|
|
|
'split-repo (%s)' % split_repo_path
|
|
|
|
if split_repo_path else 'monorepo',
|
2019-07-12 18:40:46 +02:00
|
|
|
's' if len(revs) != 1 else '',
|
|
|
|
'\n'.join(' ' + git('show', '--oneline', '--quiet', c)
|
|
|
|
for c in revs)))
|
2019-07-30 17:25:14 +02:00
|
|
|
|
|
|
|
# Ask confirmation if multiple commits are about to be pushed
|
2019-08-21 18:03:34 +02:00
|
|
|
if not args.force and len(revs) > 1:
|
2019-08-03 20:53:52 +02:00
|
|
|
if not ask_confirm("Are you sure you want to create %d commits?" % len(revs)):
|
2019-07-30 17:25:14 +02:00
|
|
|
die("Aborting")
|
|
|
|
|
2016-11-07 21:00:47 +01:00
|
|
|
for r in revs:
|
2018-11-16 23:36:17 +01:00
|
|
|
clean_svn(svn_root)
|
2019-07-12 18:40:46 +02:00
|
|
|
svn_push_one_rev(svn_root, r, git_to_svn_mapping, dry_run)
|
2016-11-07 21:00:47 +01:00
|
|
|
|
|
|
|
|
2019-03-28 17:15:28 +01:00
|
|
|
def lookup_llvm_svn_id(git_commit_hash):
|
[git] Be more specific when looking for llvm-svn
Summary:
A commit may, for some reason, have `llvm-svn:` in it multiple times. It may even take up the whole line and look identical to what gets added automatically when svn commits land in github.
To workaround this, make changes to both lookups:
1) When doing the git -> svn lookup, make sure to go through the whole message, and:
a) Only look for llvm-svn starting at the beginning of the line (excluding the whitespace that `git log` adds).
b) Take the last one (at the end of the commit message), if there are multiple matches.
2) When doing the svn -> git lookup, look through a sizeable but still reasonably small number of git commits (10k, about 4-5 months right now), and:
a) Only consider commits with the '^llvm-svn: NNNNNN' we expect, and
b) Only consider those that also follow the same git -> svn matching above. (Error if it's not exactly one commit).
Reviewers: jyknight
Reviewed By: jyknight
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60017
llvm-svn: 361532
2019-05-23 20:43:19 +02:00
|
|
|
# Use --format=%b to get the raw commit message, without any extra
|
|
|
|
# whitespace.
|
|
|
|
commit_msg = git('log', '-1', '--format=%b', git_commit_hash,
|
|
|
|
ignore_errors=True)
|
2019-03-28 17:15:28 +01:00
|
|
|
if len(commit_msg) == 0:
|
2019-07-12 18:41:28 +02:00
|
|
|
die("Can't find git commit " + git_commit_hash)
|
[git] Be more specific when looking for llvm-svn
Summary:
A commit may, for some reason, have `llvm-svn:` in it multiple times. It may even take up the whole line and look identical to what gets added automatically when svn commits land in github.
To workaround this, make changes to both lookups:
1) When doing the git -> svn lookup, make sure to go through the whole message, and:
a) Only look for llvm-svn starting at the beginning of the line (excluding the whitespace that `git log` adds).
b) Take the last one (at the end of the commit message), if there are multiple matches.
2) When doing the svn -> git lookup, look through a sizeable but still reasonably small number of git commits (10k, about 4-5 months right now), and:
a) Only consider commits with the '^llvm-svn: NNNNNN' we expect, and
b) Only consider those that also follow the same git -> svn matching above. (Error if it's not exactly one commit).
Reviewers: jyknight
Reviewed By: jyknight
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60017
llvm-svn: 361532
2019-05-23 20:43:19 +02:00
|
|
|
# If a commit has multiple "llvm-svn:" lines (e.g. if the commit is
|
|
|
|
# reverting/quoting a previous commit), choose the last one, which should
|
|
|
|
# be the authoritative one.
|
|
|
|
svn_match_iter = re.finditer('^llvm-svn: (\d{5,7})$', commit_msg,
|
|
|
|
re.MULTILINE)
|
|
|
|
svn_match = None
|
|
|
|
for m in svn_match_iter:
|
2019-07-12 18:41:28 +02:00
|
|
|
svn_match = m.group(1)
|
2019-03-28 17:15:28 +01:00
|
|
|
if svn_match:
|
2019-07-12 18:41:28 +02:00
|
|
|
return int(svn_match)
|
2019-03-28 17:15:28 +01:00
|
|
|
die("Can't find svn revision in git commit " + git_commit_hash)
|
|
|
|
|
|
|
|
|
|
|
|
def cmd_svn_lookup(args):
|
|
|
|
'''Find the SVN revision id for a given git commit hash.
|
|
|
|
|
|
|
|
This is identified by 'llvm-svn: NNNNNN' in the git commit message.'''
|
|
|
|
# Get the git root
|
|
|
|
git_root = git('rev-parse', '--show-toplevel')
|
|
|
|
if not os.path.isdir(git_root):
|
|
|
|
die("Can't find git root dir")
|
|
|
|
|
|
|
|
# Run commands from the root
|
|
|
|
os.chdir(git_root)
|
|
|
|
|
|
|
|
log('r' + str(lookup_llvm_svn_id(args.git_commit_hash)))
|
|
|
|
|
|
|
|
|
[git] Be more specific when looking for llvm-svn
Summary:
A commit may, for some reason, have `llvm-svn:` in it multiple times. It may even take up the whole line and look identical to what gets added automatically when svn commits land in github.
To workaround this, make changes to both lookups:
1) When doing the git -> svn lookup, make sure to go through the whole message, and:
a) Only look for llvm-svn starting at the beginning of the line (excluding the whitespace that `git log` adds).
b) Take the last one (at the end of the commit message), if there are multiple matches.
2) When doing the svn -> git lookup, look through a sizeable but still reasonably small number of git commits (10k, about 4-5 months right now), and:
a) Only consider commits with the '^llvm-svn: NNNNNN' we expect, and
b) Only consider those that also follow the same git -> svn matching above. (Error if it's not exactly one commit).
Reviewers: jyknight
Reviewed By: jyknight
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60017
llvm-svn: 361532
2019-05-23 20:43:19 +02:00
|
|
|
def git_hash_by_svn_rev(svn_rev):
|
|
|
|
'''Find the git hash for a given svn revision.
|
|
|
|
|
|
|
|
This check is paranoid: 'llvm-svn: NNNNNN' could exist on its own line
|
|
|
|
somewhere else in the commit message. Look in the full log message to see
|
|
|
|
if it's actually on the last line.
|
|
|
|
|
|
|
|
Since this check is expensive (we're searching every single commit), limit
|
|
|
|
to the past 10k commits (about 5 months).
|
|
|
|
'''
|
|
|
|
possible_hashes = git(
|
|
|
|
'log', '--format=%H', '--grep', '^llvm-svn: %d$' % svn_rev,
|
|
|
|
'HEAD~10000...HEAD').split('\n')
|
|
|
|
matching_hashes = [h for h in possible_hashes
|
|
|
|
if lookup_llvm_svn_id(h) == svn_rev]
|
|
|
|
if len(matching_hashes) > 1:
|
2019-07-12 18:41:28 +02:00
|
|
|
die("svn revision r%d has ambiguous commits: %s" % (
|
|
|
|
svn_rev, ', '.join(matching_hashes)))
|
[git] Be more specific when looking for llvm-svn
Summary:
A commit may, for some reason, have `llvm-svn:` in it multiple times. It may even take up the whole line and look identical to what gets added automatically when svn commits land in github.
To workaround this, make changes to both lookups:
1) When doing the git -> svn lookup, make sure to go through the whole message, and:
a) Only look for llvm-svn starting at the beginning of the line (excluding the whitespace that `git log` adds).
b) Take the last one (at the end of the commit message), if there are multiple matches.
2) When doing the svn -> git lookup, look through a sizeable but still reasonably small number of git commits (10k, about 4-5 months right now), and:
a) Only consider commits with the '^llvm-svn: NNNNNN' we expect, and
b) Only consider those that also follow the same git -> svn matching above. (Error if it's not exactly one commit).
Reviewers: jyknight
Reviewed By: jyknight
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60017
llvm-svn: 361532
2019-05-23 20:43:19 +02:00
|
|
|
elif len(matching_hashes) < 1:
|
2019-07-12 18:41:28 +02:00
|
|
|
die("svn revision r%d matches no commits" % svn_rev)
|
[git] Be more specific when looking for llvm-svn
Summary:
A commit may, for some reason, have `llvm-svn:` in it multiple times. It may even take up the whole line and look identical to what gets added automatically when svn commits land in github.
To workaround this, make changes to both lookups:
1) When doing the git -> svn lookup, make sure to go through the whole message, and:
a) Only look for llvm-svn starting at the beginning of the line (excluding the whitespace that `git log` adds).
b) Take the last one (at the end of the commit message), if there are multiple matches.
2) When doing the svn -> git lookup, look through a sizeable but still reasonably small number of git commits (10k, about 4-5 months right now), and:
a) Only consider commits with the '^llvm-svn: NNNNNN' we expect, and
b) Only consider those that also follow the same git -> svn matching above. (Error if it's not exactly one commit).
Reviewers: jyknight
Reviewed By: jyknight
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60017
llvm-svn: 361532
2019-05-23 20:43:19 +02:00
|
|
|
return matching_hashes[0]
|
|
|
|
|
2019-07-12 18:41:28 +02:00
|
|
|
|
2019-03-28 17:15:28 +01:00
|
|
|
def cmd_revert(args):
|
|
|
|
'''Revert a commit by either SVN id (rNNNNNN) or git hash. This also
|
|
|
|
populates the git commit message with both the SVN revision and git hash of
|
|
|
|
the change being reverted.'''
|
|
|
|
|
|
|
|
# Get the git root
|
|
|
|
git_root = git('rev-parse', '--show-toplevel')
|
|
|
|
if not os.path.isdir(git_root):
|
|
|
|
die("Can't find git root dir")
|
|
|
|
|
|
|
|
# Run commands from the root
|
|
|
|
os.chdir(git_root)
|
|
|
|
|
|
|
|
# Check for a client branch first.
|
|
|
|
open_files = git('status', '-uno', '-s', '--porcelain')
|
|
|
|
if len(open_files) > 0:
|
2019-07-12 18:41:28 +02:00
|
|
|
die("Found open files. Please stash and then revert.\n" + open_files)
|
2019-03-28 17:15:28 +01:00
|
|
|
|
2019-08-13 19:19:53 +02:00
|
|
|
# If the revision looks like rNNNNNN (or with a callsign, e.g. rLLDNNNNNN),
|
|
|
|
# use that. Otherwise, look for it in the git commit.
|
|
|
|
svn_match = re.match('^r[A-Z]*(\d{5,7})$', args.revision)
|
2019-03-28 17:15:28 +01:00
|
|
|
if svn_match:
|
2019-07-12 18:41:28 +02:00
|
|
|
# If the revision looks like rNNNNNN, use that as the svn revision, and
|
|
|
|
# grep through git commits to find which one corresponds to that svn
|
|
|
|
# revision.
|
|
|
|
svn_rev = int(svn_match.group(1))
|
|
|
|
git_hash = git_hash_by_svn_rev(svn_rev)
|
2019-03-28 17:15:28 +01:00
|
|
|
else:
|
2019-07-12 18:41:28 +02:00
|
|
|
# Otherwise, this looks like a git hash, so we just need to grab the
|
|
|
|
# svn revision from the end of the commit message. Get the actual git
|
|
|
|
# hash in case the revision is something like "HEAD~1"
|
|
|
|
git_hash = git('rev-parse', '--verify', args.revision + '^{commit}')
|
|
|
|
svn_rev = lookup_llvm_svn_id(git_hash)
|
2019-03-28 17:15:28 +01:00
|
|
|
|
[git] Be more specific when looking for llvm-svn
Summary:
A commit may, for some reason, have `llvm-svn:` in it multiple times. It may even take up the whole line and look identical to what gets added automatically when svn commits land in github.
To workaround this, make changes to both lookups:
1) When doing the git -> svn lookup, make sure to go through the whole message, and:
a) Only look for llvm-svn starting at the beginning of the line (excluding the whitespace that `git log` adds).
b) Take the last one (at the end of the commit message), if there are multiple matches.
2) When doing the svn -> git lookup, look through a sizeable but still reasonably small number of git commits (10k, about 4-5 months right now), and:
a) Only consider commits with the '^llvm-svn: NNNNNN' we expect, and
b) Only consider those that also follow the same git -> svn matching above. (Error if it's not exactly one commit).
Reviewers: jyknight
Reviewed By: jyknight
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60017
llvm-svn: 361532
2019-05-23 20:43:19 +02:00
|
|
|
msg = git('log', '-1', '--format=%s', git_hash)
|
2019-03-28 17:15:28 +01:00
|
|
|
|
[git] Be more specific when looking for llvm-svn
Summary:
A commit may, for some reason, have `llvm-svn:` in it multiple times. It may even take up the whole line and look identical to what gets added automatically when svn commits land in github.
To workaround this, make changes to both lookups:
1) When doing the git -> svn lookup, make sure to go through the whole message, and:
a) Only look for llvm-svn starting at the beginning of the line (excluding the whitespace that `git log` adds).
b) Take the last one (at the end of the commit message), if there are multiple matches.
2) When doing the svn -> git lookup, look through a sizeable but still reasonably small number of git commits (10k, about 4-5 months right now), and:
a) Only consider commits with the '^llvm-svn: NNNNNN' we expect, and
b) Only consider those that also follow the same git -> svn matching above. (Error if it's not exactly one commit).
Reviewers: jyknight
Reviewed By: jyknight
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60017
llvm-svn: 361532
2019-05-23 20:43:19 +02:00
|
|
|
log_verbose('Ready to revert r%d (%s): "%s"' % (svn_rev, git_hash, msg))
|
2019-03-28 17:15:28 +01:00
|
|
|
|
|
|
|
revert_args = ['revert', '--no-commit', git_hash]
|
|
|
|
# TODO: Running --edit doesn't seem to work, with errors that stdin is not
|
|
|
|
# a tty.
|
|
|
|
commit_args = [
|
|
|
|
'commit', '-m', 'Revert ' + msg,
|
[git] Be more specific when looking for llvm-svn
Summary:
A commit may, for some reason, have `llvm-svn:` in it multiple times. It may even take up the whole line and look identical to what gets added automatically when svn commits land in github.
To workaround this, make changes to both lookups:
1) When doing the git -> svn lookup, make sure to go through the whole message, and:
a) Only look for llvm-svn starting at the beginning of the line (excluding the whitespace that `git log` adds).
b) Take the last one (at the end of the commit message), if there are multiple matches.
2) When doing the svn -> git lookup, look through a sizeable but still reasonably small number of git commits (10k, about 4-5 months right now), and:
a) Only consider commits with the '^llvm-svn: NNNNNN' we expect, and
b) Only consider those that also follow the same git -> svn matching above. (Error if it's not exactly one commit).
Reviewers: jyknight
Reviewed By: jyknight
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60017
llvm-svn: 361532
2019-05-23 20:43:19 +02:00
|
|
|
'-m', 'This reverts r%d (git commit %s)' % (svn_rev, git_hash)]
|
2019-03-28 17:15:28 +01:00
|
|
|
if args.dry_run:
|
2019-07-12 18:41:28 +02:00
|
|
|
log("Would have run the following commands, if this weren't a"
|
|
|
|
"dry run:\n"
|
|
|
|
'1) git %s\n2) git %s' % (
|
|
|
|
' '.join(quote(arg) for arg in revert_args),
|
|
|
|
' '.join(quote(arg) for arg in commit_args)))
|
|
|
|
return
|
2019-03-28 17:15:28 +01:00
|
|
|
|
|
|
|
git(*revert_args)
|
|
|
|
commit_log = git(*commit_args)
|
|
|
|
|
[git] Be more specific when looking for llvm-svn
Summary:
A commit may, for some reason, have `llvm-svn:` in it multiple times. It may even take up the whole line and look identical to what gets added automatically when svn commits land in github.
To workaround this, make changes to both lookups:
1) When doing the git -> svn lookup, make sure to go through the whole message, and:
a) Only look for llvm-svn starting at the beginning of the line (excluding the whitespace that `git log` adds).
b) Take the last one (at the end of the commit message), if there are multiple matches.
2) When doing the svn -> git lookup, look through a sizeable but still reasonably small number of git commits (10k, about 4-5 months right now), and:
a) Only consider commits with the '^llvm-svn: NNNNNN' we expect, and
b) Only consider those that also follow the same git -> svn matching above. (Error if it's not exactly one commit).
Reviewers: jyknight
Reviewed By: jyknight
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60017
llvm-svn: 361532
2019-05-23 20:43:19 +02:00
|
|
|
log('Created revert of r%d: %s' % (svn_rev, commit_log))
|
2019-03-28 17:15:28 +01:00
|
|
|
log("Run 'git llvm push -n' to inspect your changes and "
|
|
|
|
"run 'git llvm push' when ready")
|
|
|
|
|
2019-07-12 18:41:28 +02:00
|
|
|
|
2016-11-07 21:00:47 +01:00
|
|
|
if __name__ == '__main__':
|
2017-05-23 23:50:40 +02:00
|
|
|
if not program_exists('svn'):
|
|
|
|
die('error: git-llvm needs svn command, but svn is not installed.')
|
|
|
|
|
2016-11-07 21:00:47 +01:00
|
|
|
argv = sys.argv[1:]
|
|
|
|
p = argparse.ArgumentParser(
|
|
|
|
prog='git llvm', formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
|
|
description=__doc__)
|
|
|
|
subcommands = p.add_subparsers(title='subcommands',
|
|
|
|
description='valid subcommands',
|
|
|
|
help='additional help')
|
|
|
|
verbosity_group = p.add_mutually_exclusive_group()
|
|
|
|
verbosity_group.add_argument('-q', '--quiet', action='store_true',
|
|
|
|
help='print less information')
|
|
|
|
verbosity_group.add_argument('-v', '--verbose', action='store_true',
|
|
|
|
help='print more information')
|
|
|
|
|
|
|
|
parser_push = subcommands.add_parser(
|
|
|
|
'push', description=cmd_push.__doc__,
|
|
|
|
help='push changes back to the LLVM SVN repository')
|
|
|
|
parser_push.add_argument(
|
|
|
|
'-n',
|
|
|
|
'--dry-run',
|
|
|
|
dest='dry_run',
|
|
|
|
action='store_true',
|
|
|
|
help='Do everything other than commit to svn. Leaves junk in the svn '
|
|
|
|
'repo, so probably will not work well if you try to commit more '
|
|
|
|
'than one rev.')
|
2019-08-21 17:41:20 +02:00
|
|
|
parser_push.add_argument(
|
|
|
|
'-f',
|
|
|
|
'--force',
|
|
|
|
action='store_true',
|
|
|
|
help='Do not ask for confirmation when pushing multiple commits.')
|
2016-11-07 21:00:47 +01:00
|
|
|
parser_push.add_argument(
|
|
|
|
'rev_range',
|
|
|
|
metavar='GIT_REVS',
|
|
|
|
type=str,
|
|
|
|
nargs='?',
|
2019-09-10 03:26:36 +02:00
|
|
|
help="revs to push (default: everything not in the branch's "
|
|
|
|
'upstream, or not in origin/master if the branch lacks '
|
|
|
|
'an explicit upstream)')
|
2016-11-07 21:00:47 +01:00
|
|
|
parser_push.set_defaults(func=cmd_push)
|
2019-03-28 17:15:28 +01:00
|
|
|
|
|
|
|
parser_revert = subcommands.add_parser(
|
|
|
|
'revert', description=cmd_revert.__doc__,
|
|
|
|
help='Revert a commit locally.')
|
|
|
|
parser_revert.add_argument(
|
|
|
|
'revision',
|
|
|
|
help='Revision to revert. Can either be an SVN revision number '
|
|
|
|
"(rNNNNNN) or a git commit hash (anything that doesn't look "
|
|
|
|
'like an SVN revision number).')
|
|
|
|
parser_revert.add_argument(
|
|
|
|
'-n',
|
|
|
|
'--dry-run',
|
|
|
|
dest='dry_run',
|
|
|
|
action='store_true',
|
|
|
|
help='Do everything other than perform a revert. Prints the git '
|
|
|
|
'revert command it would have run.')
|
|
|
|
parser_revert.set_defaults(func=cmd_revert)
|
|
|
|
|
|
|
|
parser_svn_lookup = subcommands.add_parser(
|
|
|
|
'svn-lookup', description=cmd_svn_lookup.__doc__,
|
|
|
|
help='Find the llvm-svn revision for a given commit.')
|
|
|
|
parser_svn_lookup.add_argument(
|
|
|
|
'git_commit_hash',
|
|
|
|
help='git_commit_hash for which we will look up the svn revision id.')
|
|
|
|
parser_svn_lookup.set_defaults(func=cmd_svn_lookup)
|
|
|
|
|
2016-11-07 21:00:47 +01:00
|
|
|
args = p.parse_args(argv)
|
|
|
|
VERBOSE = args.verbose
|
|
|
|
QUIET = args.quiet
|
|
|
|
|
2019-07-30 17:25:11 +02:00
|
|
|
# Python3 workaround, for when not arguments are provided.
|
|
|
|
# See https://bugs.python.org/issue16308
|
|
|
|
try:
|
|
|
|
func = args.func
|
|
|
|
except AttributeError:
|
|
|
|
# No arguments or subcommands were given.
|
|
|
|
parser.print_help()
|
|
|
|
parser.exit()
|
|
|
|
|
2016-11-07 21:00:47 +01:00
|
|
|
# Dispatch to the right subcommand
|
|
|
|
args.func(args)
|