Skip to content

Commit 9b4aaca

Browse files
committed
Prefer to only use 'git describe' for all required info
Previously, three git commands were used to gather all required info. Now all info is gathered from a single 'git describe' call in all usual cases, and only if that fails fallbacks are used. The --dirty option was already present before commit 929a5d7, but it was removed to address [1], which turns out to not actually be necessary as we can try "git describe --dirty" first and then eventually use the fallback. [1] #86
1 parent 9bd1298 commit 9b4aaca

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ v1.15.1
1515

1616
* fix issue #126: the local part of any tags is discarded
1717
when guessing new versions
18+
* minor performance optimization by doing fewer git calls
19+
in the usual cases
20+
1821

1922
v1.15.0
2023
=======

setuptools_scm/git.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import warnings
55

66
FILES_COMMAND = 'git ls-files'
7-
DEFAULT_DESCRIBE = 'git describe --tags --long --match *.*'
7+
DEFAULT_DESCRIBE = 'git describe --dirty --tags --long --match *.*'
88

99

1010
def _normalized(path):
@@ -83,21 +83,31 @@ def parse(root, describe_command=DEFAULT_DESCRIBE, pre_parse=warn_on_shallow):
8383
return
8484
if pre_parse:
8585
pre_parse(wd)
86-
rev_node = wd.node()
87-
dirty = wd.is_dirty()
88-
89-
if rev_node is None:
90-
return meta('0.0', distance=0, dirty=dirty)
9186

9287
out, err, ret = do_ex(describe_command, root)
9388
if ret:
89+
# If 'git describe' failed, try to get the information otherwise.
90+
rev_node = wd.node()
91+
dirty = wd.is_dirty()
92+
93+
if rev_node is None:
94+
return meta('0.0', distance=0, dirty=dirty)
95+
9496
return meta(
9597
'0.0',
9698
distance=wd.count_all_nodes(),
9799
node=rev_node,
98100
dirty=dirty,
99101
)
100102

103+
# 'out' looks e.g. like 'v1.5.0-0-g4060507' or
104+
# 'v1.15.1rc1-37-g9bd1298-dirty'.
105+
if out.endswith('-dirty'):
106+
dirty = True
107+
out = out[:-6]
108+
else:
109+
dirty = False
110+
101111
tag, number, node = out.rsplit('-', 2)
102112
number = int(number)
103113
if number:

0 commit comments

Comments
 (0)