Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submodule support #79

Closed
wants to merge 20 commits into from
Closed

Submodule support #79

wants to merge 20 commits into from

Conversation

nemui
Copy link

@nemui nemui commented Mar 3, 2020

Hello, this is for #52

I'm not too sure how to correctly support submodules, to be honest, but this seems to be working for my use case: pushing tags on each build for the parent repository and its submodules, in other words, we rely on tags being the same across the repository.

What do you think?

I have also added a simple check for when toRef and fromRef are the same, #62 - in this case we return an empty list of tags.

@tomasbjerre
Copy link
Owner

I'll put this on my todo-list.

@nemui
Copy link
Author

nemui commented Mar 4, 2020

I have a better idea on how to handle submodules.
Instead of relying on specified refs to exist in all submodules, how about simply returning the diff between the current and the previous submodule hashes?

E.g. in the parent repo, we have
commits A, B, C
And in a submodule we have commits D, E and F
A -> D
B -> D
C -> F

When diffing between A and C, we will also show the diff between D and F for commit C

@tomasbjerre
Copy link
Owner

Sounds good!

@nemui
Copy link
Author

nemui commented Mar 4, 2020

Great, I'll update the pull request once I have it working.

@nemui
Copy link
Author

nemui commented Apr 10, 2020

How does this look? I've opted out of having submodule changes per commit, as it makes the changelog too noisy, especially when mulitiple commits reference the same changes in submodules, e.g. via branch merges.

Instead, I diff submodules between the earliest and the latest commit mentioned in the parent repository for any given diffset.

@tomasbjerre
Copy link
Owner

This is on my todo-list. Will have a look later.

@@ -380,6 +379,12 @@ public GitChangelogApi withSettings(final URL url) {
return this;
}

/** {@link Settings}. */
public GitChangelogApi withSettings(final Settings settings) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont like to expose Settings in the API.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a better way to provide an existing Settings object?


public GitRepo() {
this.repository = null;
this.revWalk = null;
this.submodules = null;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer an empty map here, not null

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

}
}
} else {
this.submodules = null;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not be needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -89,6 +105,11 @@ public void close() throws IOException {
LOG.error(e.getMessage(), e);
}
}
if (submodules != null) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if is not needed, if changing to empty map as default value.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -142,6 +163,45 @@ public ObjectId getRef(final String fromRef) throws GitChangelogRepositoryExcept
throw new GitChangelogRepositoryException(fromRef + " not found in:\n" + toString());
}

public boolean hasSubmodules() {
return submodules != null && submodules.size() > 0;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This null-check is not needed, if changing to empty map as default value.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

commit = this.revWalk.parseCommit(getCommit(commitHash));
prevCommit = commit.getParentCount() > 0 ? commit.getParent(0) : null;
} catch (GitChangelogRepositoryException | IOException e) {
e.printStackTrace();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw GitChangelogRepositoryException

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

diffFormatter.format(diffFormatter.toFileHeader(entry));
}
} catch (IOException e) {
e.printStackTrace();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw GitChangelogRepositoryException

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

try {
return new CanonicalTreeParser(null, reader, treeId);
} catch (IOException e) {
e.printStackTrace();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw GitChangelogRepositoryException

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

.withSettings(settings)
.getChangelog(useIntegrationIfConfigured));
} catch (GitChangelogRepositoryException e) {
e.printStackTrace();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw GitChangelogRepositoryException

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@nemui
Copy link
Author

nemui commented Sep 10, 2020

Hi @tomasbjerre , I have added a couple of test cases.

The stuff that is added to GitRepo can probably be refactored out of there with a describing name for it.

Something like GitRepoWithSubmodules class that inherits from GitRepo? Or is there an easier way to get access to repository and revWalk class members from GitRepo, as submodule functionality makes use of those?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants