commit: 381fad5e3554ec94ec5626e8c17874f32b30b752
Author: Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Tue Aug 29 07:26:36 2023 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Apr 26 22:05:48 2024 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=381fad5e
lib: use more pure git-describe output for --version
Use `git describe --dirty` output rather than mangling git-describe and
reinventing
--dirty by manually checking for changes post-commit.
We no longer mangle the 7th commit post-tag into _p7, but instead do:
${tag}-7-${last_commit}.
This is similar to gnulib's git-version-gen (which we may still want to import,
not sure, this seems enough for now) and is familiar output for developers.
Example:
* Old: 3.0.51_p7
* New: 3.0.51-7-g098b30548
Bug: https://bugs.gentoo.org/912209
Signed-off-by: Sam James <sam <AT> gentoo.org>
lib/portage/__init__.py | 35 ++++-------------------------------
1 file changed, 4 insertions(+), 31 deletions(-)
diff --git a/lib/portage/__init__.py b/lib/portage/__init__.py
index aa81bdb4c2..a468eeaff3 100644
--- a/lib/portage/__init__.py
+++ b/lib/portage/__init__.py
@@ -720,10 +720,7 @@ if installation.TYPE == installation.TYPES.SOURCE:
BASH_BINARY,
"-c",
(
- f"cd {_shell_quote(PORTAGE_BASE_PATH)} ; git describe
--match 'portage-*' || exit $? ; "
- 'if [ -n "`git diff-index --name-only --diff-filter=M
HEAD`" ] ; '
- "then echo modified ; git rev-list --format=%%ct -n 1
HEAD ; fi ; "
- "exit 0"
+ f"cd {_shell_quote(PORTAGE_BASE_PATH)} ; git describe
--dirty --match 'portage-*' || exit $? ; "
),
]
cmd = [
@@ -735,33 +732,9 @@ if installation.TYPE == installation.TYPES.SOURCE:
output = _unicode_decode(proc.communicate()[0],
encoding=encoding)
status = proc.wait()
if os.WIFEXITED(status) and os.WEXITSTATUS(status) == os.EX_OK:
- output_lines = output.splitlines()
- if output_lines:
- version_split = output_lines[0].split("-")
- if len(version_split) > 1:
- VERSION = version_split[1]
- patchlevel = False
- if len(version_split) > 2:
- patchlevel = True
- VERSION = f"{VERSION}_p{version_split[2]}"
- if len(output_lines) > 1 and output_lines[1] ==
"modified":
- head_timestamp = None
- if len(output_lines) > 3:
- try:
- head_timestamp = int(output_lines[3])
- except ValueError:
- pass
- timestamp = int(time.time())
- if (
- head_timestamp is not None
- and timestamp > head_timestamp
- ):
- timestamp = timestamp - head_timestamp
- if not patchlevel:
- VERSION = f"{VERSION}_p0"
- VERSION = f"{VERSION}_p{timestamp}"
- return VERSION
- VERSION = "HEAD"
+ VERSION = output.lstrip('portage-').strip()
+ else:
+ VERSION = "HEAD"
return VERSION
VERSION = _LazyVersion()