You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by gh...@apache.org on 2023/10/23 16:47:23 UTC

[kafka] branch 3.5 updated: KAFKA-14767: Fix missing commitId build error after git gc (#13315)

This is an automated email from the ASF dual-hosted git repository.

gharris pushed a commit to branch 3.5
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/3.5 by this push:
     new a6a893796e6 KAFKA-14767: Fix missing commitId build error after git gc (#13315)
a6a893796e6 is described below

commit a6a893796e695e09e87ce36d883b0efcba3e99ba
Author: Greg Harris <gr...@aiven.io>
AuthorDate: Sun Oct 22 11:08:01 2023 -0700

    KAFKA-14767: Fix missing commitId build error after git gc (#13315)
    
    git gc moves commit hashes from individual .git/refs/heads/ to .git/packed-refs which is not read
    by the determineCommitId function.
    
    Replace the existing lookup within the .git directory with a GrGit lookup that handles packed and
    unpacked refs transparently.
    
    Reviewers: Ismael Juma <is...@juma.me.uk>
---
 build.gradle | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/build.gradle b/build.gradle
index 59318878e11..081fe036dc4 100644
--- a/build.gradle
+++ b/build.gradle
@@ -107,6 +107,7 @@ ext {
     throw new GradleException("Unexpected value for scalaOptimizerMode property. Expected one of $scalaOptimizerValues, but received: $userScalaOptimizerMode")
 
   generatedDocsDir = new File("${project.rootDir}/docs/generated")
+  repo = file("$rootDir/.git").isDirectory() ? Grgit.open(currentDir: project.getRootDir()) : null
 
   commitId = determineCommitId()
 }
@@ -162,16 +163,8 @@ def determineCommitId() {
   def takeFromHash = 16
   if (project.hasProperty('commitId')) {
     commitId.take(takeFromHash)
-  } else if (file("$rootDir/.git/HEAD").exists()) {
-    def headRef = file("$rootDir/.git/HEAD").text
-    if (headRef.contains('ref: ')) {
-      headRef = headRef.replaceAll('ref: ', '').trim()
-      if (file("$rootDir/.git/$headRef").exists()) {
-        file("$rootDir/.git/$headRef").text.trim().take(takeFromHash)
-      }
-    } else {
-      headRef.trim().take(takeFromHash)
-    }
+  } else if (repo != null) {
+    repo.head().id.take(takeFromHash)
   } else {
     "unknown"
   }
@@ -179,7 +172,7 @@ def determineCommitId() {
 
 apply from: file('wrapper.gradle')
 
-if (file('.git').exists()) {
+if (repo != null) {
   rat {
     verbose.set(true)
     reportDir.set(project.file('build/rat'))
@@ -187,7 +180,6 @@ if (file('.git').exists()) {
 
     // Exclude everything under the directory that git should be ignoring via .gitignore or that isn't checked in. These
     // restrict us only to files that are checked in or are staged.
-    def repo = Grgit.open(currentDir: project.getRootDir())
     excludes = new ArrayList<String>(repo.clean(ignore: false, directories: true, dryRun: true))
     // And some of the files that we have checked in should also be excluded from this check
     excludes.addAll([