Skip to content

Commit 51b5682

Browse files
committed
Minor improvement of getRevisionNumber logic
1 parent f31ea1e commit 51b5682

File tree

3 files changed

+26
-30
lines changed

3 files changed

+26
-30
lines changed

data/txt/sha256sums.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ a033f92d136c707a25927c2383125ddb004d4283db62c004dcd67c3fc242bb1c lib/core/dump.
187187
49c0fa7e3814dfda610d665ee02b12df299b28bc0b6773815b4395514ddf8dec lib/core/profiling.py
188188
03db48f02c3d07a047ddb8fe33a757b6238867352d8ddda2a83e4fec09a98d04 lib/core/readlineng.py
189189
48797d6c34dd9bb8a53f7f3794c85f4288d82a9a1d6be7fcf317d388cb20d4b3 lib/core/replication.py
190-
3574639db4942d16a2dc0a2f04bb7c0913c40c3862b54d34c44075a760e0c194 lib/core/revision.py
190+
0b8c38a01bb01f843d94a6c5f2075ee47520d0c4aa799cecea9c3e2c5a4a23a6 lib/core/revision.py
191191
888daba83fd4a34e9503fe21f01fef4cc730e5cde871b1d40e15d4cbc847d56c lib/core/session.py
192-
0072bbc61a2a9129b25736f97ccd2a326ca977ef707f8a9dd8db67b41f7553a0 lib/core/settings.py
192+
7f08f592c49c3534afc931a7fb9e1915ffa7425e66ada1d58e56e3383758440f lib/core/settings.py
193193
cd5a66deee8963ba8e7e9af3dd36eb5e8127d4d68698811c29e789655f507f82 lib/core/shell.py
194194
bcb5d8090d5e3e0ef2a586ba09ba80eef0c6d51feb0f611ed25299fbb254f725 lib/core/subprocessng.py
195195
d35650179816193164a5f177102f18379dfbe6bb6d40fbb67b78d907b41c8038 lib/core/target.py

lib/core/revision.py

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,43 +22,39 @@ def getRevisionNumber():
2222

2323
retVal = None
2424
filePath = None
25-
_ = os.path.dirname(__file__)
25+
directory = os.path.dirname(__file__)
2626

2727
while True:
28-
filePath = os.path.join(_, ".git", "HEAD")
29-
if os.path.exists(filePath):
28+
candidate = os.path.join(directory, ".git", "HEAD")
29+
if os.path.exists(candidate):
30+
filePath = candidate
3031
break
31-
else:
32-
filePath = None
33-
if _ == os.path.dirname(_):
34-
break
35-
else:
36-
_ = os.path.dirname(_)
3732

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
33+
parent = os.path.dirname(directory)
34+
if parent == directory:
35+
break
36+
directory = parent
4337

44-
if content.startswith("ref: "):
45-
try:
46-
filePath = os.path.join(_, ".git", content.replace("ref: ", "")).strip()
47-
except UnicodeError:
48-
pass
38+
if filePath:
39+
with openFile(filePath, "r") as f:
40+
content = getText(f.read()).strip()
4941

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
42+
if content.startswith("ref: "):
43+
ref_path = content.replace("ref: ", "").strip()
44+
filePath = os.path.join(directory, ".git", ref_path)
45+
46+
if os.path.exists(filePath):
47+
with openFile(filePath, "r") as f_ref:
48+
content = getText(f_ref.read()).strip()
49+
50+
match = re.match(r"(?i)[0-9a-f]{40}", content)
51+
retVal = match.group(0) if match else None
5652

5753
if not retVal:
5854
try:
59-
process = subprocess.Popen("git rev-parse --verify HEAD", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
55+
process = subprocess.Popen(["git", "rev-parse", "--verify", "HEAD"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
6056
stdout, _ = process.communicate()
61-
match = re.search(r"(?i)[0-9a-f]{32}", getText(stdout or ""))
57+
match = re.search(r"(?i)[0-9a-f]{40}", getText(stdout or ""))
6258
retVal = match.group(0) if match else None
6359
except:
6460
pass

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from thirdparty import six
2020

2121
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
22-
VERSION = "1.10.1.58"
22+
VERSION = "1.10.1.59"
2323
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2424
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2525
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

0 commit comments

Comments
 (0)