MCPcopy Index your code
hub / github.com/sqlmapproject/sqlmap / getRevisionNumber

Function getRevisionNumber

lib/core/revision.py:15–66  ·  view source on GitHub ↗

Returns abbreviated commit hash number as retrieved with "git rev-parse --short HEAD" >>> len(getRevisionNumber() or (' ' * 7)) == 7 True

()

Source from the content-addressed store, hash-verified

13from lib.core.convert import getText
14
15def getRevisionNumber():
16 """
17 Returns abbreviated commit hash number as retrieved with "git rev-parse --short HEAD"
18
19 >>> len(getRevisionNumber() or (' ' * 7)) == 7
20 True
21 """
22
23 retVal = None
24 filePath = None
25 _ = os.path.dirname(__file__)
26
27 while True:
28 filePath = os.path.join(_, ".git", "HEAD")
29 if os.path.exists(filePath):
30 break
31 else:
32 filePath = None
33 if _ == os.path.dirname(_):
34 break
35 else:
36 _ = os.path.dirname(_)
37
38 while True:
39 if filePath and os.path.isfile(filePath):
40 with openFile(filePath, "r") as f:
41 content = getText(f.read())
42 filePath = None
43
44 if content.startswith("ref: "):
45 try:
46 filePath = os.path.join(_, ".git", content.replace("ref: ", "")).strip()
47 except UnicodeError:
48 pass
49
50 if filePath is None:
51 match = re.match(r"(?i)[0-9a-f]{32}", content)
52 retVal = match.group(0) if match else None
53 break
54 else:
55 break
56
57 if not retVal:
58 try:
59 process = subprocess.Popen("git rev-parse --verify HEAD", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
60 stdout, _ = process.communicate()
61 match = re.search(r"(?i)[0-9a-f]{32}", getText(stdout or ""))
62 retVal = match.group(0) if match else None
63 except:
64 pass
65
66 return retVal[:7] if retVal else None

Callers 1

updateFunction · 0.90

Calls 6

openFileFunction · 0.90
getTextFunction · 0.90
readMethod · 0.45
replaceMethod · 0.45
matchMethod · 0.45
searchMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…