diff options
author | Sam James <sam@gentoo.org> | 2023-08-29 08:26:36 +0100 |
---|---|---|
committer | Sam James <sam@gentoo.org> | 2024-04-26 23:05:48 +0100 |
commit | 381fad5e3554ec94ec5626e8c17874f32b30b752 (patch) | |
tree | c0c685514ab3c10c9d7ab7e815f1972ae836f185 | |
parent | Remove QA warning when no bash completions are found (diff) | |
download | portage-381fad5e3554ec94ec5626e8c17874f32b30b752.tar.gz portage-381fad5e3554ec94ec5626e8c17874f32b30b752.tar.bz2 portage-381fad5e3554ec94ec5626e8c17874f32b30b752.zip |
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@gentoo.org>
-rw-r--r-- | lib/portage/__init__.py | 35 |
1 files changed, 4 insertions, 31 deletions
diff --git a/lib/portage/__init__.py b/lib/portage/__init__.py index aa81bdb4c..a468eeaff 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() |