Skip to content

Commit

Permalink
Use abbreviated hash in build metedata
Browse files Browse the repository at this point in the history
Since the commit ID is only used for metadata on insignificant versions,
there's no reason to be so concerned about uniqueness that we use a full
hash. It will be easier for users to deal with if its shorter. Using the
ObjectReader method in this change, does ensure uniqueness within the
current repo, which is all we really need anyway.

This fixes #86.
  • Loading branch information
ajoberstar committed Jul 4, 2018
1 parent 08fd339 commit b130896
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
Expand Down Expand Up @@ -55,7 +56,7 @@ public GitInventorySupplier(Repository repo, Function<String, Optional<String>>
@Override
public VcsInventory getInventory() {
// share this walk throughout to benefit from its caching
try (RevWalk walk = new RevWalk(repo)) {
try (ObjectReader reader = repo.newObjectReader(); RevWalk walk = new RevWalk(reader)) {
// saves on some performance as we don't really need the commit bodys
walk.setRetainBody(false);

Expand Down Expand Up @@ -94,7 +95,7 @@ public VcsInventory getInventory() {
Set<Version> claimedVersions = taggedVersions.stream().map(TaggedVersion::getVersion).collect(Collectors.toSet());

return new VcsInventory(
headObjectId.getName(),
reader.abbreviate(headObjectId).name(),
isClean(),
currentVersion,
baseVersion.getVersion(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class GitInventorySupplierTest extends Specification {

GitInventorySupplier supplier

def 'commit id is abbreviated, not full'() {
expect:
supplier.getInventory().commitId == Optional.of(grgit.head().abbreviatedId)
}

def 'if HEAD has no tagged versions, current version is empty'() {
given:
checkout('head-untagged')
Expand Down

0 comments on commit b130896

Please sign in to comment.