Download:
child 124:b3411bba76ac
parent 122:357d231b6f76
123:beb8f09f4bbb
Anton Shestakov <av6@dwimlabs.net>, Thu, 07 Jul 2016 14:11:03 +0800
checker: support git

2 файлов изменено, 46 вставок(+), 2 удалений(-) [+]
checker.py file | annotate | diff | comparison | revisions
incoming.py file | annotate | diff | comparison | revisions
--- a/checker.py Thu Jul 07 14:09:07 2016 +0800
+++ b/checker.py Thu Jul 07 14:11:03 2016 +0800
@@ -4,6 +4,7 @@
import os
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
@@ -73,21 +74,38 @@
if 'scm' not in config:
print("# C&O config doesn't have 'scm' defined.")
ok = False
- elif config['scm'] != 'hg':
+ elif config['scm'] not in ('git', 'hg'):
print("# C&O checker doesn't support {} yet.".format(config['scm']))
ok = False
return ok
+def git_clone(url, dest):
+ return run(['git', 'clone', '--depth', '1', url, dest])
+
+
def hg_clone(url, dest):
return run(['hg', 'clone', url, dest])
+def git_status():
+ return run(['git', 'status'])
+
+
def hg_summary():
return run(['hg', 'sum'])
+def git_show():
+ 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)
+
+
def hg_log():
template = (r'# C&O commit: {rev}:{node}\n'
r'# C&O commit branch: {branch}\n'
@@ -97,6 +115,17 @@
return run(['hg', 'log', '-r', '.', '-T', template], silent=True)
+def git_files(include, exclude):
+ cmd = ['git', 'ls-files']
+ cmd.extend(include)
+ files = run(cmd, silent=True, get_output=True)
+ if files is not False:
+ files = files.splitlines()
+ for e in exclude:
+ files = [f for f in files if not fnmatchcase(f, e)]
+ return files
+
+
def hg_files(include, exclude):
cmd = ['hg', 'files']
for pat in include:
@@ -121,6 +150,9 @@
if config['scm'] == 'hg':
os.environ['HGPLAIN'] = '1'
+ if config['scm'] == 'git':
+ if not git_clone(config['url'], source):
+ return False
if config['scm'] == 'hg':
if not hg_clone(config['url'], source):
return False
@@ -128,10 +160,16 @@
print('$ cd {}'.format(source))
os.chdir(source)
+ if config['scm'] == 'git':
+ if not git_status():
+ return False
if config['scm'] == 'hg':
if not hg_summary():
return False
+ if config['scm'] == 'git':
+ if not git_show():
+ return False
if config['scm'] == 'hg':
if not hg_log():
return False
@@ -174,6 +212,8 @@
if linter['name'] not in linter_config:
continue
+ if config['scm'] == 'git':
+ files = git_files(linter['include'], linter.get('exclude', []))
if config['scm'] == 'hg':
files = hg_files(linter['include'], linter.get('exclude', []))
if files is False:
--- a/incoming.py Thu Jul 07 14:09:07 2016 +0800
+++ b/incoming.py Thu Jul 07 14:11:03 2016 +0800
@@ -130,7 +130,7 @@
if m is not None:
url = m.group(1)
- m = re.match('^commit: (\d+):(\w+)$', rest)
+ m = re.match('^commit: (?:(\d+):)?(\w+)$', rest)
if m is not None:
rev = m.group(1)
node = m.group(2)
@@ -139,6 +139,10 @@
if m is not None:
branch = m.group(1)
+ m = re.match('^commit ref names:.* HEAD -> (\S+)(, |$)', rest)
+ if m is not None:
+ branch = m.group(1)
+
m = re.match('^commit date: (.+)$', rest)
if m is not None:
date = m.group(1)