Skip to content

Commit

Permalink
[FIXED JENKINS-29326] Don't add duplicate BuildData.
Browse files Browse the repository at this point in the history
Added equals methods to BuildData and Build, and check if we already
have an equivalent BuildData on a build before we add it, the git tag
action and changelog, so that we avoid duplicate records of all these things.
  • Loading branch information
abayer committed Dec 10, 2015
1 parent f00f379 commit b4a4c7d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/main/java/hudson/plugins/git/GitSCM.java
Expand Up @@ -1038,7 +1038,7 @@ public void checkout(Run<?, ?> build, Launcher launcher, FilePath workspace, Tas

BuildData previousBuildData = getBuildData(build.getPreviousBuild()); // read only
BuildData buildData = copyBuildData(build.getPreviousBuild());
build.addAction(buildData);

if (VERBOSE && buildData.lastBuild != null) {
listener.getLogger().println("Last Built Revision: " + buildData.lastBuild.revision);
}
Expand Down Expand Up @@ -1068,16 +1068,20 @@ public void checkout(Run<?, ?> build, Launcher launcher, FilePath workspace, Tas

try {
checkoutCommand.execute();
} catch(GitLockFailedException e) {
} catch (GitLockFailedException e) {
// Rethrow IOException so the retry will be able to catch it
throw new IOException("Could not checkout " + revToBuild.revision.getSha1String(), e);
}

build.addAction(new GitTagAction(build, workspace, revToBuild.revision));
// Don't add the tag and changelog if we've already processed this BuildData before.
if (!build.getActions(BuildData.class).contains(buildData)) {
build.addAction(buildData);
build.addAction(new GitTagAction(build, workspace, revToBuild.revision));

if (changelogFile != null) {
computeChangeLog(git, revToBuild.revision, listener, previousBuildData, new FilePath(changelogFile),
new BuildChooserContextImpl(build.getParent(), build, environment));
if (changelogFile != null) {
computeChangeLog(git, revToBuild.revision, listener, previousBuildData, new FilePath(changelogFile),
new BuildChooserContextImpl(build.getParent(), build, environment));
}
}

for (GitSCMExtension ext : extensions) {
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/hudson/plugins/git/util/Build.java
Expand Up @@ -91,6 +91,21 @@ public Result getBuildResult() {
return "Build #" + hudsonBuildNumber + " of " + revision.toString();
}

@Override
public boolean equals(Object o) {
if (!(o instanceof Build)) {
return false;
} else {
Build otherBuild = (Build) o;
if (otherBuild.hudsonBuildNumber == this.hudsonBuildNumber
&& otherBuild.revision.equals(this.revision)) {
return true;
} else {
return false;
}
}
}

@Override
public Build clone() {
Build clone;
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/hudson/plugins/git/util/BuildData.java
Expand Up @@ -16,7 +16,6 @@
import java.util.*;

import static hudson.Util.fixNull;

/**
* Captures the Git related information for a build.
*
Expand Down Expand Up @@ -245,6 +244,23 @@ public String toString() {
",lastBuild="+lastBuild+"]";
}

@Override
public boolean equals(Object o) {
if (!(o instanceof BuildData)) {
return false;
} else {
BuildData otherBuildData = (BuildData) o;

if (otherBuildData.remoteUrls.equals(this.remoteUrls)
&& otherBuildData.buildsByBranchName.equals(this.buildsByBranchName)
&& otherBuildData.lastBuild.equals(this.lastBuild)) {
return true;
} else {
return false;
}
}
}

/**
* Remove branches from BuildData that have been seen in the past but do not exist anymore
* @param keepBranches all branches available in current repository state
Expand Down

0 comments on commit b4a4c7d

Please sign in to comment.