--- a/checker.py Thu Jul 07 14:09:07 2016 +0800
+++ b/checker.py Thu Jul 07 14:11:03 2016 +0800
from argparse import ArgumentParser, FileType
from datetime import datetime
+from fnmatch import fnmatchcase
from shutil import rmtree
from subprocess import check_call, check_output, CalledProcessError
from tempfile import mkdtemp
print("# C&O config doesn't have 'scm' defined.")
- elif config['scm'] != 'hg':
+ elif config['scm'] not in ('git', 'hg'):
print("# C&O checker doesn't support {} yet.".format(config['scm']))
+def git_clone(url, dest):
+ return run(['git', 'clone', '--depth', '1', url, dest])
return run(['hg', 'clone', url, dest])
+ return run(['git', 'status'])
return run(['hg', 'sum'])
+ template = (r'# C&O commit: %H%n'
+ r'# C&O commit ref names: %D%n'
+ r'# C&O commit date: %ai%n'
+ r'# C&O commit author: %aN%n'
+ r'# C&O commit message: %s%n')
+ return run(['git', 'show', '-q', '--format=format:' + template], silent=True)
template = (r'# C&O commit: {rev}:{node}\n'
r'# C&O commit branch: {branch}\n'
return run(['hg', 'log', '-r', '.', '-T', template], silent=True)
+def git_files(include, exclude):
+ cmd = ['git', 'ls-files']
+ files = run(cmd, silent=True, get_output=True)
+ files = files.splitlines()
+ files = [f for f in files if not fnmatchcase(f, e)]
def hg_files(include, exclude):
if config['scm'] == 'hg':
os.environ['HGPLAIN'] = '1'
+ if config['scm'] == 'git':
+ if not git_clone(config['url'], source):
if config['scm'] == 'hg':
if not hg_clone(config['url'], source):
print('$ cd {}'.format(source))
+ if config['scm'] == 'git':
if config['scm'] == 'hg':
+ if config['scm'] == 'git':
if config['scm'] == 'hg':
if linter['name'] not in linter_config:
+ if config['scm'] == 'git':
+ files = git_files(linter['include'], linter.get('exclude', []))
if config['scm'] == 'hg':
files = hg_files(linter['include'], linter.get('exclude', []))