1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

Fix some minor coding-style issues in git-llvm.

llvm-svn: 365918
This commit is contained in:
James Y Knight 2019-07-12 16:41:28 +00:00
parent 902e0a60c1
commit 443f7255d2

View File

@ -18,14 +18,11 @@ This file provides integration for git.
from __future__ import print_function
import argparse
import collections
import contextlib
import errno
import os
import re
import shutil
import subprocess
import sys
import tempfile
import time
assert sys.version_info >= (2, 7)
@ -73,7 +70,7 @@ LLVM_MONOREPO_SVN_MAPPING = {
LLVM_MONOREPO_SVN_MAPPING.update({'clang': 'cfe/trunk'})
LLVM_MONOREPO_SVN_MAPPING.update({'': 'monorepo-root/trunk'})
SPLIT_REPO_NAMES = {'llvm-' + d : d + '/trunk'
SPLIT_REPO_NAMES = {'llvm-' + d: d + '/trunk'
for d in ['www', 'zorg', 'test-suite', 'lnt']}
VERBOSE = False
@ -167,6 +164,7 @@ def git(*cmd, **kwargs):
def svn(cwd, *cmd, **kwargs):
return shell(['svn'] + list(cmd), cwd=cwd, **kwargs)
def program_exists(cmd):
if sys.platform == 'win32' and not cmd.endswith('.exe'):
cmd += '.exe'
@ -175,6 +173,7 @@ def program_exists(cmd):
return True
return False
def get_default_rev_range():
# Get the branch tracked by the current branch, as set by
# git branch --set-upstream-to See http://serverfault.com/a/352236/38694.
@ -277,6 +276,7 @@ def fix_eol_style_native(rev, svn_sr_path, files):
# just the diff, and not a mass line ending change.
shell(['dos2unix'] + crlf_files, ignore_errors=True, cwd=svn_sr_path)
def split_subrepo(f, git_to_svn_mapping):
# Given a path, splits it into (subproject, rest-of-path). If the path is
# not in a subproject, returns ('', full-path).
@ -288,6 +288,7 @@ def split_subrepo(f, git_to_svn_mapping):
else:
return '', f
def get_all_parent_dirs(name):
parts = []
head, tail = os.path.split(name)
@ -296,6 +297,7 @@ def get_all_parent_dirs(name):
head, tail = os.path.split(head)
return parts
def svn_push_one_rev(svn_repo, rev, git_to_svn_mapping, dry_run):
files = git('diff-tree', '--no-commit-id', '--name-only', '-r',
rev).split('\n')
@ -320,7 +322,8 @@ def svn_push_one_rev(svn_repo, rev, git_to_svn_mapping, dry_run):
svn_dirs_to_update.add(
os.path.dirname(os.path.join(svn_sr_path, f)))
# We also need to svn update any parent directories which are not yet present
# We also need to svn update any parent directories which are not yet
# present
parent_dirs = set()
for dir in svn_dirs_to_update:
parent_dirs.update(get_all_parent_dirs(dir))
@ -419,7 +422,8 @@ def cmd_push(args):
revs = get_revs_to_push(rev_range)
log('Pushing %d %s commit%s:\n%s' %
(len(revs),
'split-repo (%s)' % split_repo_path if split_repo_path else 'monorepo',
'split-repo (%s)' % split_repo_path
if split_repo_path else 'monorepo',
's' if len(revs) != 1 else '',
'\n'.join(' ' + git('show', '--oneline', '--quiet', c)
for c in revs)))
@ -485,6 +489,7 @@ def git_hash_by_svn_rev(svn_rev):
die("svn revision r%d matches no commits" % svn_rev)
return matching_hashes[0]
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
@ -513,9 +518,9 @@ def cmd_revert(args):
svn_rev = int(svn_match.group(1))
git_hash = git_hash_by_svn_rev(svn_rev)
else:
# 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"
# 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)
@ -530,7 +535,8 @@ def cmd_revert(args):
'commit', '-m', 'Revert ' + msg,
'-m', 'This reverts r%d (git commit %s)' % (svn_rev, git_hash)]
if args.dry_run:
log("Would have run the following commands, if this weren't a dry run:\n"
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)))
@ -543,6 +549,7 @@ def cmd_revert(args):
log("Run 'git llvm push -n' to inspect your changes and "
"run 'git llvm push' when ready")
if __name__ == '__main__':
if not program_exists('svn'):
die('error: git-llvm needs svn command, but svn is not installed.')