Skip to content

Conversation

abatkin
Copy link
Contributor

@abatkin abatkin commented Dec 2, 2014

Tested with both JGit and native git. Handles both staged and unstaged commits.

@@ -59,6 +59,7 @@
public static final String BRANCH = "branch";
public static final String COMMIT_ID = "commit.id";
public static final String COMMIT_ID_ABBREV = "commit.id.abbrev";
public static final String FILES_DIRTY = "files.dirty";
Copy link
Collaborator

Choose a reason for hiding this comment

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

does not match any naming convention.
please previx with commit.id

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that it doesn't match any naming convention, but it's also not part of the commit id or anything like that. This particular property has more to do with the files on the filesystem than anything else though. It's easy enough for me to change the name, but I don't think that "commit.id.files.dirty" (or anything starting "commit.id") is really intuitive. "commit.files.dirty" maybe?

@ktoso
Copy link
Collaborator

ktoso commented Dec 2, 2014

please include a test for this property if you'd like to see this merged (and address review feedback) :)
thanks in advance

@ktoso
Copy link
Collaborator

ktoso commented Dec 3, 2014

Thanks for updating the PR (and the test)!
I'll review in more detail today later on. You're right that the naming of this new property isn't directly a commit thing... let's think of a good name for it hm hm

@abatkin
Copy link
Contributor Author

abatkin commented Dec 4, 2014

Thinking more, maybe even commit.dirty would work?

@ktoso
Copy link
Collaborator

ktoso commented Dec 5, 2014

I was thinking that it's not really a property of the commit, but of the repository, so git.repository.dirty sounds the best to me so far... I think this commit is already nice enough so I might just merge and update the docs / name of the prop today :-)

@dtrucken
Copy link
Contributor

dtrucken commented Dec 5, 2014

I could use this one (in addition to pull #143) immediately!

ktoso added a commit that referenced this pull request Dec 6, 2014
add boolean property: 'files.dirty' if working dir is dirty
@ktoso ktoso merged commit f497bf1 into git-commit-id:master Dec 6, 2014
@ktoso
Copy link
Collaborator

ktoso commented Dec 6, 2014

Merged – I'll do some more cleanups this weekend and cut a release tomorrow night :)
Thanks for the contribution!

@abatkin
Copy link
Contributor Author

abatkin commented Dec 7, 2014

You rock. Thanks for the feedback (i.e. forcing me to write a unit test) and for merging.

@ktoso ktoso added this to the 2.1.12 milestone Dec 8, 2014
@ktoso
Copy link
Collaborator

ktoso commented Dec 8, 2014

Thanks for the kudos, and the PR!

This is now available as git.dirty, and will ship in a few minutes as 2.1.12 :-)

I reimplemented the native checking as well, so it's faster now.

@@ -176,6 +176,12 @@ protected String getAbbrevCommitId() throws MojoExecutionException {
}

@Override
protected boolean isDirty() throws MojoExecutionException {
String output = tryToRunGitCommand(canonical, "status --porcelain");
Copy link
Collaborator

Choose a reason for hiding this comment

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

this was very expensive, I have reimplemented it to not kill performance on large dirty repositories :-)
This impl has to wait for the entire status to return, while we only want to know if it's more than 0 lines. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds reasonable. But I'm curious if -s is really faster than --porcelain? On my system both produce the same output (the former being colorized, assuming git thinks it is talking to a tty). On the largest repo I could quickly find (linux kernel) both performed identically (~100ms after 10 runs).

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's not the speed up change.
The speed up change is to not collect the entire output into a string and then check isEmpty() - way too costly. Instead as I described above, we return once there's a line of output. See https://github.com/ktoso/maven-git-commit-id-plugin/blob/master/src/main/java/pl/project13/maven/git/NativeGitProvider.java#L363

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh, I missed that.

  1. Doesn't waitFor() wait for the process to exit? So you may not have to sit around reading all of the input in, but git still has to run to completion
  2. This won't work on Windows systems

Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. it's still way faster than consuming the stream into string, as in - doesn't kill my build
  2. I don't think the native impl ever worked on windows.

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