Skip to content

Commit

Permalink
fix: fix the mismatch between Go and Java on the Git entity serializa…
Browse files Browse the repository at this point in the history
…tion #332 (#335)
  • Loading branch information
flelli authored Oct 31, 2024
2 parents 46e6450 + a718db5 commit 539d3fd
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 27 deletions.
14 changes: 14 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Nyx Release Notes

## 3.0.10

This release is available at [this link](https://github.com/mooltiverse/nyx/releases/tag/3.0.10).

### Upgrade instructions

There are no actions to take for backward compatibility.

### New features and improvements

This release:

* fixes the mismatch between Go and Java on the Git entity serialization ([#332](https://github.com/mooltiverse/nyx/issues/332))

## 3.0.9

This release is available at [this link](https://github.com/mooltiverse/nyx/releases/tag/3.0.9).
Expand Down
2 changes: 1 addition & 1 deletion modules/go/nyx/entities/git/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ as all internal fields must be exported (have the first capital letter in their
*/
type Action struct {
// The identity.
Identity Identity `json:"identity" yaml:"identity"`
Identity Identity `json:"identity,omitempty" yaml:"identity,omitempty"`

// The time stamp.
TimeStamp TimeStamp `json:"timeStamp,omitempty" yaml:"timeStamp,omitempty"`
Expand Down
12 changes: 6 additions & 6 deletions modules/go/nyx/entities/git/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ as all internal fields must be exported (have the first capital letter in their
*/
type Commit struct {
// The author data
AuthorAction Action `json:"authorAction" yaml:"authorAction"`
AuthorAction Action `json:"authorAction,omitempty" yaml:"authorAction,omitempty"`

// The committer data
CommitAction Action `json:"commitAction" yaml:"commitAction"`
CommitAction Action `json:"commitAction,omitempty" yaml:"commitAction,omitempty"`

// The commit date
Date int64 `json:"date,omitempty" yaml:"date,omitempty"`

// The commit message
Message Message `json:"message" yaml:"message"`
Message Message `json:"message,omitempty" yaml:"message,omitempty"`

// The parents SHA's.
Parents []string `json:"parents" yaml:"parents"`
Parents []string `json:"parents,omitempty" yaml:"parents,omitempty"`

// The tags associated to the commit.
Tags []Tag `json:"tags" yaml:"tags"`
Tags []Tag `json:"tags,omitempty" yaml:"tags,omitempty"`

// The commit SHA-1 identifier.
Sha string `json:"sha" yaml:"sha"`
Sha string `json:"sha,omitempty" yaml:"sha,omitempty"`
}

/*
Expand Down
2 changes: 1 addition & 1 deletion modules/go/nyx/entities/git/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Identity struct {
Email string `json:"email,omitempty" yaml:"email,omitempty"`

// The name.
Name string `json:"name" yaml:"name"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
}

/*
Expand Down
4 changes: 2 additions & 2 deletions modules/go/nyx/entities/git/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ type Message struct {
Footers map[string]string `json:"footers,omitempty" yaml:"footers,omitempty"`

// The full message.
FullMessage string `json:"fullMessage" yaml:"fullMessage"`
FullMessage string `json:"fullMessage,omitempty" yaml:"fullMessage,omitempty"`

// The short message.
ShortMessage string `json:"shortMessage" yaml:"shortMessage"`
ShortMessage string `json:"shortMessage,omitempty" yaml:"shortMessage,omitempty"`
}

/*
Expand Down
6 changes: 3 additions & 3 deletions modules/go/nyx/entities/git/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ as all internal fields must be exported (have the first capital letter in their
*/
type Tag struct {
// The annotated or lightweight flag.
Annotated bool `json:"annotated,omitempty" yaml:"annotated"`
Annotated bool `json:"annotated,omitempty" yaml:"annotated,omitempty"`

// The name.
Name string `json:"name" yaml:"name"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`

// The tagged object ID.
Target string `json:"target" yaml:"target"`
Target string `json:"target,omitempty" yaml:"target,omitempty"`
}

/*
Expand Down
2 changes: 1 addition & 1 deletion modules/go/nyx/entities/git/time_stamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ as all internal fields must be exported (have the first capital letter in their
*/
type TimeStamp struct {
// The time stamp.
TimeStamp int64 `json:"timeStamp" yaml:"timeStamp"`
TimeStamp int64 `json:"timeStamp,omitempty" yaml:"timeStamp,omitempty"`

// The time zone offset in minutes relative to UTC.
Offset *int `json:"offset,omitempty" yaml:"offset,omitempty"`
Expand Down
8 changes: 4 additions & 4 deletions modules/go/nyx/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,8 +705,8 @@ func TestStateSaveAndResumeJSON(t *testing.T) {
configuration.WithRuntimeConfiguration(&cl)
oldState, _ := NewStateWith(configuration)

initialCommit := gitent.NewCommitWith("b50926577d36f403f4b3ebf51dfe34660b52eaa2", 1580515200, []string{}, *gitent.NewActionWith(*gitent.NewIdentityWith("Jim", "jim@example.com"), *gitent.NewTimeStampWithIn(time.Now().UnixMilli(), utl.PointerToInt(0))), *gitent.NewActionWith(*gitent.NewIdentityWith("Jim", "jim@example.com"), *gitent.NewTimeStampWithIn(time.Now().UnixMilli(), utl.PointerToInt(0))), *gitent.NewMessageWith("initial commit", "initial commit", nil), []gitent.Tag{})
finalCommit := gitent.NewCommitWith("e6b1c65eac4d81aadde22e796bb2a8e48da4c5d9", 1730308844000, []string{"b50926577d36f403f4b3ebf51dfe34660b52eaa2"}, *gitent.NewActionWith(*gitent.NewIdentityWith("Jim", "jim@example.com"), *gitent.NewTimeStampWithIn(time.Now().UnixMilli(), utl.PointerToInt(-120))), *gitent.NewActionWith(*gitent.NewIdentityWith("Jim", "jim@example.com"), *gitent.NewTimeStampWithIn(time.Now().UnixMilli(), utl.PointerToInt(-120))), *gitent.NewMessageWith("final commit", "final commit", nil), []gitent.Tag{})
initialCommit := gitent.NewCommitWith("b50926577d36f403f4b3ebf51dfe34660b52eaa2", 1580515200, nil, *gitent.NewActionWith(*gitent.NewIdentityWith("Jim", "jim@example.com"), *gitent.NewTimeStampWithIn(time.Now().UnixMilli(), utl.PointerToInt(0))), *gitent.NewActionWith(*gitent.NewIdentityWith("Jim", "jim@example.com"), *gitent.NewTimeStampWithIn(time.Now().UnixMilli(), utl.PointerToInt(0))), *gitent.NewMessageWith("initial commit", "initial commit", nil), nil)
finalCommit := gitent.NewCommitWith("e6b1c65eac4d81aadde22e796bb2a8e48da4c5d9", 1730308844000, []string{"b50926577d36f403f4b3ebf51dfe34660b52eaa2"}, *gitent.NewActionWith(*gitent.NewIdentityWith("Jim", "jim@example.com"), *gitent.NewTimeStampWithIn(time.Now().UnixMilli(), utl.PointerToInt(-120))), *gitent.NewActionWith(*gitent.NewIdentityWith("Jim", "jim@example.com"), *gitent.NewTimeStampWithIn(time.Now().UnixMilli(), utl.PointerToInt(-120))), *gitent.NewMessageWith("final commit", "final commit", nil), nil)

// set a few values to use later on for comparison
release := ent.NewReleaseWith(utl.PointerToString("MyRelease"), utl.PointerToString("today"))
Expand Down Expand Up @@ -985,8 +985,8 @@ func TestStateSaveAndResumeYAML(t *testing.T) {
configuration.WithRuntimeConfiguration(&cl)
oldState, _ := NewStateWith(configuration)

initialCommit := gitent.NewCommitWith("b50926577d36f403f4b3ebf51dfe34660b52eaa2", 1580515200, []string{}, *gitent.NewActionWith(*gitent.NewIdentityWith("Jim", "jim@example.com"), *gitent.NewTimeStampWithIn(time.Now().UnixMilli(), utl.PointerToInt(0))), *gitent.NewActionWith(*gitent.NewIdentityWith("Jim", "jim@example.com"), *gitent.NewTimeStampWithIn(time.Now().UnixMilli(), utl.PointerToInt(0))), *gitent.NewMessageWith("initial commit", "initial commit", nil), []gitent.Tag{})
finalCommit := gitent.NewCommitWith("e6b1c65eac4d81aadde22e796bb2a8e48da4c5d9", 1730308844000, []string{"b50926577d36f403f4b3ebf51dfe34660b52eaa2"}, *gitent.NewActionWith(*gitent.NewIdentityWith("Jim", "jim@example.com"), *gitent.NewTimeStampWithIn(time.Now().UnixMilli(), utl.PointerToInt(-120))), *gitent.NewActionWith(*gitent.NewIdentityWith("Jim", "jim@example.com"), *gitent.NewTimeStampWithIn(time.Now().UnixMilli(), utl.PointerToInt(-120))), *gitent.NewMessageWith("final commit", "final commit", nil), []gitent.Tag{})
initialCommit := gitent.NewCommitWith("b50926577d36f403f4b3ebf51dfe34660b52eaa2", 1580515200, nil, *gitent.NewActionWith(*gitent.NewIdentityWith("Jim", "jim@example.com"), *gitent.NewTimeStampWithIn(time.Now().UnixMilli(), utl.PointerToInt(0))), *gitent.NewActionWith(*gitent.NewIdentityWith("Jim", "jim@example.com"), *gitent.NewTimeStampWithIn(time.Now().UnixMilli(), utl.PointerToInt(0))), *gitent.NewMessageWith("initial commit", "initial commit", nil), nil)
finalCommit := gitent.NewCommitWith("e6b1c65eac4d81aadde22e796bb2a8e48da4c5d9", 1730308844000, []string{"b50926577d36f403f4b3ebf51dfe34660b52eaa2"}, *gitent.NewActionWith(*gitent.NewIdentityWith("Jim", "jim@example.com"), *gitent.NewTimeStampWithIn(time.Now().UnixMilli(), utl.PointerToInt(-120))), *gitent.NewActionWith(*gitent.NewIdentityWith("Jim", "jim@example.com"), *gitent.NewTimeStampWithIn(time.Now().UnixMilli(), utl.PointerToInt(-120))), *gitent.NewMessageWith("final commit", "final commit", nil), nil)

// set a few values to use later on for comparison
release := ent.NewReleaseWith(utl.PointerToString("MyRelease"), utl.PointerToString("today"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ public class Commit implements Comparable<Commit>, Cloneable, Serializable {
* @param authorAction the value holder about the author. Cannot be {@code null}
* @param commitAction the value holder about the committer. Cannot be {@code null}
* @param message the commit message. Cannot be {@code null}
* @param tags the tags applied to this commit. If the commit has no tags an empty,
* non {@code null} set, must be passed
* @param tags the tags applied to this commit. May be {@code null}
*/
@JsonCreator
public Commit(@JsonProperty("sha") String sha, @JsonProperty("date") long date, @JsonProperty("parents") List<String> parents, @JsonProperty("authorAction") Action authorAction, @JsonProperty("commitAction") Action commitAction, @JsonProperty("message") Message message, @JsonProperty("tags") Set<Tag> tags) {
Expand All @@ -84,22 +83,21 @@ public Commit(@JsonProperty("sha") String sha, @JsonProperty("date") long date,
Objects.requireNonNull(authorAction);
Objects.requireNonNull(commitAction);
Objects.requireNonNull(message);
Objects.requireNonNull(tags);
this.sha = sha;
this.date = date;
this.parents = Collections.unmodifiableList(parents);
this.authorAction = authorAction;
this.commitAction = commitAction;
this.message = message;
this.tags = Collections.unmodifiableSet(tags);
this.tags = tags == null ? null : Collections.unmodifiableSet(tags);
}

/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return 41 * sha.hashCode() * 37 * Long.valueOf(date).intValue() * 31 * parents.hashCode() * 29 * authorAction.hashCode() * 23 * commitAction.hashCode() * 19 * message.hashCode() * 17 * tags.hashCode();
return 41 * sha.hashCode() * 37 * Long.valueOf(date).intValue() * 31 * parents.hashCode() * 29 * authorAction.hashCode() * 23 * commitAction.hashCode() * 19 * message.hashCode() * 17 * (tags == null ? 1 : tags.hashCode());
}

/**
Expand All @@ -115,7 +113,7 @@ public boolean equals(Object obj) {
return false;

Commit other = Commit.class.cast(obj);
return getSHA().equals(other.getSHA()) && getDate() == other.getDate() && getParents().equals(other.getParents()) && getAuthorAction().equals(other.getAuthorAction()) && getCommitAction().equals(other.getCommitAction()) && getMessage().equals(other.getMessage()) && getTags().equals(other.getTags());
return getSHA().equals(other.getSHA()) && getDate() == other.getDate() && getParents().equals(other.getParents()) && getAuthorAction().equals(other.getAuthorAction()) && getCommitAction().equals(other.getCommitAction()) && getMessage().equals(other.getMessage()) && (getTags() == null ? other.getTags() == null : getTags().equals(other.getTags()));
}

/**
Expand All @@ -132,7 +130,11 @@ public int compareTo(Commit c) {
if (getAuthorAction().compareTo(c.getAuthorAction()) == 0) {
if (getCommitAction().compareTo(c.getCommitAction()) == 0) {
if (getMessage().compareTo(c.getMessage()) == 0) {
return getTags().size()-c.getTags().size();
if (getTags() == null) {
return c.getTags() == null ? 0 : c.getTags().size() * -1;
} else {
return c.getTags() == null ? getTags().size() : getTags().size()-c.getTags().size();
}
}
else return getMessage().compareTo(c.getMessage());
}
Expand Down Expand Up @@ -195,7 +197,7 @@ public List<String> getParents() {
/**
* Returns the immutable list of tags pointing to this commit.
*
* @return the immutable list of tags pointing to this commit. May be empty but not {@code null}.
* @return the immutable list of tags pointing to this commit. May be {@code null}.
*/
public Set<Tag> getTags() {
return tags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ void constructorTest()
assertThrows(NullPointerException.class, () -> new Commit("f9422bd6e5b0ac0ab0df2bffc280c3d4caa11b44", 0, parents, authorAction, commitAction, null, null));
assertThrows(NullPointerException.class, () -> new Commit("f9422bd6e5b0ac0ab0df2bffc280c3d4caa11b44", 0, parents, authorAction, null, message, null));
assertThrows(NullPointerException.class, () -> new Commit("f9422bd6e5b0ac0ab0df2bffc280c3d4caa11b44", 0, parents, authorAction, null, null, tags));
assertThrows(NullPointerException.class, () -> new Commit("f9422bd6e5b0ac0ab0df2bffc280c3d4caa11b44", 0, parents, authorAction, commitAction, message, null));
assertThrows(NullPointerException.class, () -> new Commit("f9422bd6e5b0ac0ab0df2bffc280c3d4caa11b44", 0, parents, authorAction, commitAction, null, tags));
}
}

0 comments on commit 539d3fd

Please sign in to comment.