Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Issue #704: Use built in git-describe #705

Merged
merged 8 commits into from
Mar 29, 2023
Merged

Conversation

esword
Copy link
Contributor

@esword esword commented Mar 28, 2023

Before this PR

Addresses Issue #704

After this PR

==COMMIT_MSG==
Use built in git-describe
==COMMIT_MSG==

Possible downsides?

Will require version of git <10 years old. If you consider that a downside.

@changelog-app
Copy link

changelog-app bot commented Mar 28, 2023

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Use built in git-describe rather than an expensive recreation of it to support older versions of git. This version requires git version >=1.8.4 (released 23rd August 2013).

Check the box to generate changelog(s)

  • Generate changelog entry

src/main/java/com/palantir/gradle/gitversion/Git.java Outdated Show resolved Hide resolved
@@ -56,7 +57,7 @@ private boolean isClean() {
private String description() {
String rawDescription = expensiveComputeRawDescription();
String processedDescription =
rawDescription == null ? null : rawDescription.replaceFirst("^" + args.getPrefix(), "");
Strings.isNullOrEmpty(rawDescription) ? null : rawDescription.replaceFirst("^" + args.getPrefix(), "");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Would prefer if we didn't change this. Treating the empty string the same as null can result in subtle bugs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one we need to change because the describe method no longer returns a null (that is, wraps a thrown exception) when the result is an empty string. The previous implementation erroneously threw an exception because it would try to truncate the empty string when git returned no found result.

I think it's still okay because it is at this single chokepoint and passes the null on up so that all the rest of the code that calls this still behaves the same.

We could check for empty string in Git.describe() and return a null instead, but that seems worse than this.

I did do some extra cleanup of removing the unnecessary extra method in VersionDetailsImpl - The expensiveComputeRawDescription method is no longer needed since we are not caching the resulting value anymore (from Yiwen's change a couple of months ago).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could check for empty string in Git.describe() and return a null instead, but that seems worse than this.

I think I would prefer this, primarily because it removes ambiguity from the contract of describe and avoids leaking concerns across function boundaries. Null means the operation failed, non-null means the operation succeeds - callers don't have think about the empty string case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the return value of Git.describe() to an Optional<String> would be an even better solution, making this contract very clear to callers.

Copy link
Member

@pkoenig10 pkoenig10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@bulldozer-bot bulldozer-bot bot merged commit 8e380cc into develop Mar 29, 2023
@bulldozer-bot bulldozer-bot bot deleted the esword/use_git_describe branch March 29, 2023 16:29
@svc-autorelease
Copy link
Collaborator

Refusing to release a major rev - please do this manually at https://autorelease.general.dmz.palantir.tech/palantir/gradle-git-version

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants