Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-17604] Better equals for Git
  • Loading branch information
wolfgarnet committed Apr 14, 2013
1 parent 7ed417b commit c81f647
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
Expand Up @@ -40,6 +40,33 @@ public void checkout( FilePath workspace, TaskListener listener ) throws IOExcep
}
}

@Override
public boolean equals( Object other ) {
if( other == this ) {
return true;
}

if( other instanceof GitConfiguration ) {
GitConfiguration o = (GitConfiguration) other;
/* Check size */
if( o.getList().size() != list.size() ) {
return false;
}

/* Check elements, the size is identical */
for( int i = 0; i < list.size(); ++i ) {
if( !o.list.get( i ).equals( list.get( i ) ) ) {
return false;
}
}

/* Everything is ok */
return true;
} else {

This comment has been minimized.

Copy link
@MadsNielsen

MadsNielsen Apr 17, 2013

Member

Shouldn't you return false here? If you pass in another kind of object the current git configuration would be equal to any kind of other object?

return true;
}
}

@Override
public List<ConfigRotatorChangeLogEntry> difference( GitConfigurationComponent component, GitConfigurationComponent other ) throws ConfigurationRotatorException {
return null; //To change body of implemented methods use File | Settings | File Templates.
Expand Down
Expand Up @@ -86,9 +86,27 @@ public String getFeedName() {
return repository;
}

@Override
public boolean equals( Object other ) {
if( other == this ) {
return true;
}

if( other instanceof GitConfigurationComponent ) {
GitConfigurationComponent o = (GitConfigurationComponent) other;

logger.finest( "Other: " + o.commitId + " == " + commitId );

return ( o.commitId.equals( commitId ) && ( o.isFixed() == fixed ) );
} else {
return false;
}
}

@Override
public String toString() {
return "GitComponent[" + name + ": " + repository + ", " + branch + ", " + commitId + "]";
//return "GitComponent[" + name + ": " + repository + ", " + branch + ", " + commitId + "]";
return "GC[" + commitId + "]";
}

@Override
Expand Down
Expand Up @@ -82,7 +82,8 @@ public boolean equals( Object other ) {
if( other instanceof GitTarget ) {
GitTarget o = (GitTarget)other;

return repository.equals( o.repository );
//return repository.equals( o.repository );
return commitId.equals( o.commitId );
} else {
return false;
}
Expand Down

0 comments on commit c81f647

Please sign in to comment.