Commit e204c596 authored by lieryan's avatar lieryan Committed by Robby Russell
Browse files

Rewrite gitstatus collection to be more robust (#7322)

Fix the finicky parsing logic and just ask git the necessary information
directly.
parent feaee044
...@@ -4,26 +4,21 @@ from __future__ import print_function ...@@ -4,26 +4,21 @@ from __future__ import print_function
import os import os
import sys import sys
import re import re
import shlex
from subprocess import Popen, PIPE, check_output from subprocess import Popen, PIPE, check_output
def get_tagname_or_hash(): def get_tagname_or_hash():
"""return tagname if exists else hash""" """return tagname if exists else hash"""
cmd = 'git log -1 --format="%h%d"'
output = check_output(shlex.split(cmd)).decode('utf-8').strip()
hash_, tagname = None, None
# get hash # get hash
m = re.search('\(.*\)$', output) hash_cmd = ['git', 'rev-parse', '--short', 'HEAD']
if m: hash_ = check_output(hash_cmd).strip()
hash_ = output[:m.start()-1]
# get tagname # get tagname
m = re.search('tag: .*[,\)]', output) tags_cmd = ['git', 'for-each-ref', '--points-at=HEAD', '--count=2', '--sort=-version:refname', '--format=%(refname:short)', 'refs/tags']
if m: tags = check_output(tags_cmd).split()
tagname = 'tags/' + output[m.start()+len('tag: '): m.end()-1]
if tagname: if tags:
return tagname.replace(' ', '') return tags[0] + ('+' if len(tags) > 1 else '')
elif hash_: elif hash_:
return hash_ return hash_
return None return None
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment