python 速度测试获取refname和hash

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 速度测试获取refname和hash相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function
import time
import re
import subprocess

# git describe and rev-parse
print('w/ git desc & rev-parse')
t_start = time.time()
cmd = 'git rev-parse --short HEAD'
output = subprocess.check_output(cmd, shell=True).strip()
print('hash:', output)
cmd = 'git describe --all --exact-match HEAD'
output = subprocess.check_output(cmd, shell=True).strip()
print('refname:', output)
print('time:', time.time() - t_start)

# git log
print('--------------------------------------------------')
print('w/ git log')
t_start = time.time()
cmd = 'git log -1 --format="%h%d"'
output = subprocess.check_output(cmd, shell=True).strip()
m = re.search('\(.*\)$', output)
if m:
    print('hash:', output[:m.start()])
else:
    print('hash:', output)
m = re.search('tag: .*[,\)]', output)
if m:
    print('refname:', 'tags/'+output[m.start()+5: m.end()-1])
print('time:', time.time() - t_start)

以上是关于python 速度测试获取refname和hash的主要内容,如果未能解决你的问题,请参考以下文章