2013-02-14 15:32:17 +04:00
|
|
|
#!/usr/bin/env python
|
2011-02-07 02:25:55 +03:00
|
|
|
|
|
|
|
"""
|
2018-01-02 02:48:10 +03:00
|
|
|
Copyright (c) 2006-2018 sqlmap developers (http://sqlmap.org/)
|
2017-10-11 15:50:46 +03:00
|
|
|
See the file 'LICENSE' for copying permission
|
2011-02-07 02:25:55 +03:00
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
2016-12-20 01:47:39 +03:00
|
|
|
import subprocess
|
2011-02-07 02:25:55 +03:00
|
|
|
|
|
|
|
def getRevisionNumber():
|
2012-07-03 02:50:23 +04:00
|
|
|
"""
|
2012-07-03 15:06:52 +04:00
|
|
|
Returns abbreviated commit hash number as retrieved with "git rev-parse --short HEAD"
|
2012-07-03 02:50:23 +04:00
|
|
|
"""
|
|
|
|
|
2011-02-07 02:25:55 +03:00
|
|
|
retVal = None
|
2012-07-02 15:01:20 +04:00
|
|
|
filePath = None
|
|
|
|
_ = os.path.dirname(__file__)
|
2012-07-26 02:08:49 +04:00
|
|
|
|
2012-07-02 15:01:20 +04:00
|
|
|
while True:
|
2012-07-26 02:02:38 +04:00
|
|
|
filePath = os.path.join(_, ".git", "HEAD")
|
2012-07-02 15:01:20 +04:00
|
|
|
if os.path.exists(filePath):
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
filePath = None
|
|
|
|
if _ == os.path.dirname(_):
|
|
|
|
break
|
2011-03-08 00:54:30 +03:00
|
|
|
else:
|
2012-07-02 15:01:20 +04:00
|
|
|
_ = os.path.dirname(_)
|
2012-07-26 02:08:49 +04:00
|
|
|
|
2012-07-26 02:02:38 +04:00
|
|
|
while True:
|
|
|
|
if filePath and os.path.isfile(filePath):
|
|
|
|
with open(filePath, "r") as f:
|
|
|
|
content = f.read()
|
|
|
|
filePath = None
|
|
|
|
if content.startswith("ref: "):
|
|
|
|
filePath = os.path.join(_, ".git", content.replace("ref: ", "")).strip()
|
|
|
|
else:
|
|
|
|
match = re.match(r"(?i)[0-9a-f]{32}", content)
|
|
|
|
retVal = match.group(0) if match else None
|
|
|
|
break
|
2012-07-30 14:09:20 +04:00
|
|
|
else:
|
|
|
|
break
|
2011-03-08 00:54:30 +03:00
|
|
|
|
2012-07-02 15:01:20 +04:00
|
|
|
if not retVal:
|
2016-12-20 01:47:39 +03:00
|
|
|
process = subprocess.Popen("git rev-parse --verify HEAD", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
2012-07-02 15:01:20 +04:00
|
|
|
stdout, _ = process.communicate()
|
|
|
|
match = re.search(r"(?i)[0-9a-f]{32}", stdout or "")
|
|
|
|
retVal = match.group(0) if match else None
|
2011-02-07 02:25:55 +03:00
|
|
|
|
2012-07-03 15:06:52 +04:00
|
|
|
return retVal[:7] if retVal else None
|