asfgit closed pull request #72: [SCM-885] second implementation with new API
URL: https://github.com/apache/maven-scm/pull/72
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/maven-scm-api/src/main/java/org/apache/maven/scm/CommandParameter.java
b/maven-scm-api/src/main/java/org/apache/maven/scm/CommandParameter.java
index c8edd3541..3d695ef4f 100644
--- a/maven-scm-api/src/main/java/org/apache/maven/scm/CommandParameter.java
+++ b/maven-scm-api/src/main/java/org/apache/maven/scm/CommandParameter.java
@@ -50,6 +50,8 @@
public static final CommandParameter BRANCH = new CommandParameter(
"branch" );
+ public static final CommandParameter FROM_START_OF_REPOSITORY = new
CommandParameter( "fromStartOfRepository" );
+
public static final CommandParameter START_SCM_VERSION = new
CommandParameter( "startScmVersion" );
public static final CommandParameter END_SCM_VERSION = new
CommandParameter( "endScmVersion" );
diff --git
a/maven-scm-api/src/main/java/org/apache/maven/scm/command/changelog/AbstractChangeLogCommand.java
b/maven-scm-api/src/main/java/org/apache/maven/scm/command/changelog/AbstractChangeLogCommand.java
index b8473ab0b..b808900f0 100644
---
a/maven-scm-api/src/main/java/org/apache/maven/scm/command/changelog/AbstractChangeLogCommand.java
+++
b/maven-scm-api/src/main/java/org/apache/maven/scm/command/changelog/AbstractChangeLogCommand.java
@@ -55,6 +55,14 @@ protected ChangeLogScmResult executeChangeLogCommand(
ScmProviderRepository repo
throw new ScmException( "Unsupported method for this provider." );
}
+ protected ChangeLogScmResult executeChangeLogCommand(
ScmProviderRepository repository, ScmFileSet fileSet,
+ ScmVersion
endVersion,
+ String datePattern,
boolean fromStartOfRepository )
+ throws ScmException
+ {
+ throw new ScmException( "Unsupported method for this provider." );
+ }
+
/**
* {@inheritDoc}
*/
@@ -82,9 +90,18 @@ public ScmResult executeCommand( ScmProviderRepository
repository, ScmFileSet fi
String datePattern = parameters.getString(
CommandParameter.CHANGELOG_DATE_PATTERN, null );
+ boolean fromStartOfRepository = parameters.getBoolean(
CommandParameter.FROM_START_OF_REPOSITORY, false );
+
if ( startVersion != null || endVersion != null )
{
- return executeChangeLogCommand( repository, fileSet, startVersion,
endVersion, datePattern );
+ if ( startVersion == null && fromStartOfRepository )
+ {
+ return executeChangeLogCommand( repository, fileSet,
endVersion, datePattern, fromStartOfRepository );
+ }
+ else
+ {
+ return executeChangeLogCommand( repository, fileSet,
startVersion, endVersion, datePattern );
+ }
}
else
{
diff --git
a/maven-scm-api/src/main/java/org/apache/maven/scm/command/changelog/ChangeLogScmRequest.java
b/maven-scm-api/src/main/java/org/apache/maven/scm/command/changelog/ChangeLogScmRequest.java
index f96c12603..0fe6305f5 100644
---
a/maven-scm-api/src/main/java/org/apache/maven/scm/command/changelog/ChangeLogScmRequest.java
+++
b/maven-scm-api/src/main/java/org/apache/maven/scm/command/changelog/ChangeLogScmRequest.java
@@ -130,6 +130,18 @@ public void setEndRevision( ScmVersion endRevision )
parameters.setScmVersion( CommandParameter.END_SCM_VERSION,
endRevision );
}
+ public boolean isFromStartOfRepository()
+ throws ScmException
+ {
+ return parameters.getBoolean(
CommandParameter.FROM_START_OF_REPOSITORY, false );
+ }
+
+ public void setFromStartOfRepository()
+ throws ScmException
+ {
+ parameters.setString( CommandParameter.FROM_START_OF_REPOSITORY,
Boolean.TRUE.toString() );
+ }
+
public String getDatePattern()
throws ScmException
{
diff --git
a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogCommand.java
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogCommand.java
index 2145eeb83..41211df79 100644
---
a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogCommand.java
+++
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogCommand.java
@@ -60,6 +60,16 @@ protected ChangeLogScmResult executeChangeLogCommand(
ScmProviderRepository repo
return executeChangeLogCommand( repo, fileSet, null, null, null,
datePattern, startVersion, endVersion );
}
+ /** {@inheritDoc} */
+ protected ChangeLogScmResult executeChangeLogCommand(
ScmProviderRepository repo, ScmFileSet fileSet,
+ ScmVersion
endVersion, String datePattern,
+ boolean
fromStartOfRepository )
+ throws ScmException
+ {
+ return executeChangeLogCommand( repo, fileSet, null, null, null,
datePattern, null, endVersion, null,
+ fromStartOfRepository );
+ }
+
/** {@inheritDoc} */
protected ChangeLogScmResult executeChangeLogCommand(
ScmProviderRepository repo, ScmFileSet fileSet,
Date startDate, Date
endDate, ScmBranch branch,
@@ -89,7 +99,7 @@ protected ChangeLogScmResult executeChangeLogCommand(
ChangeLogScmRequest reques
final String datePattern = request.getDatePattern();
return executeChangeLogCommand(
request.getScmRepository().getProviderRepository(), fileSet,
request.getStartDate(), request.getEndDate(),
request.getScmBranch(), datePattern, startVersion,
- endVersion, request.getLimit() );
+ endVersion, request.getLimit(),
request.isFromStartOfRepository() );
}
protected ChangeLogScmResult executeChangeLogCommand(
ScmProviderRepository repo, ScmFileSet fileSet,
@@ -97,9 +107,21 @@ protected ChangeLogScmResult executeChangeLogCommand(
ScmProviderRepository repo
String datePattern,
ScmVersion startVersion,
ScmVersion
endVersion, Integer limit )
throws ScmException
+ {
+ return executeChangeLogCommand(
+ repo, fileSet, startDate, endDate, branch, datePattern,
startVersion, endVersion, limit, false
+ );
+ }
+
+ protected ChangeLogScmResult executeChangeLogCommand(
ScmProviderRepository repo, ScmFileSet fileSet,
+ Date startDate, Date
endDate, ScmBranch branch,
+ String datePattern,
ScmVersion startVersion,
+ ScmVersion
endVersion, Integer limit,
+ boolean
fromStartOfRepository )
+ throws ScmException
{
Commandline cl = createCommandLine( (GitScmProviderRepository) repo,
fileSet.getBasedir(), branch, startDate,
- endDate, startVersion, endVersion,
limit );
+ endDate, startVersion, endVersion,
limit, fromStartOfRepository );
GitChangeLogConsumer consumer = new GitChangeLogConsumer( getLogger(),
datePattern );
@@ -136,9 +158,18 @@ public static Commandline createCommandLine(
GitScmProviderRepository repository
null );
}
+ static Commandline createCommandLine( GitScmProviderRepository repository,
File workingDirectory,
+ ScmBranch branch, Date startDate,
Date endDate,
+ ScmVersion startVersion, ScmVersion
endVersion, Integer limit )
+ {
+ return createCommandLine( repository, workingDirectory, branch,
startDate, endDate, startVersion, endVersion,
+ limit, false );
+ }
+
static Commandline createCommandLine( GitScmProviderRepository repository,
File workingDirectory,
ScmBranch branch, Date
startDate, Date endDate,
- ScmVersion startVersion,
ScmVersion endVersion, Integer limit )
+ ScmVersion startVersion,
ScmVersion endVersion, Integer limit,
+ boolean fromStartOfRepository
)
{
SimpleDateFormat dateFormat = new SimpleDateFormat( DATE_FORMAT );
dateFormat.setTimeZone( TimeZone.getTimeZone( "GMT" ) );
@@ -166,14 +197,17 @@ static Commandline createCommandLine(
GitScmProviderRepository repository, File
if ( startVersion != null || endVersion != null )
{
StringBuilder versionRange = new StringBuilder();
-
+
if ( startVersion != null )
{
versionRange.append( StringUtils.escape(
startVersion.getName() ) );
}
- versionRange.append( ".." );
-
+ if ( startVersion != null || !fromStartOfRepository )
+ {
+ versionRange.append( ".." );
+ }
+
if ( endVersion != null )
{
versionRange.append( StringUtils.escape( endVersion.getName()
) );
diff --git
a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogCommandTest.java
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogCommandTest.java
index ecc6086fa..2fb115f3b 100644
---
a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogCommandTest.java
+++
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/changelog/GitChangeLogCommandTest.java
@@ -143,6 +143,14 @@ public void testCommandLineWithStartVersionAndEndVersion()
+ " -- " + StringUtils.quoteAndEscape(
workingDirectory.getPath(), '"' ) );
}
+ public void testCommandLineWithEndVersionStartingFromRoot()
+ throws Exception
+ {
+ testCommandLine( "scm:git:http://foo.com/git", null, new ScmRevision(
"10" ),
+ "git whatchanged --date=iso 10"
+ + " -- " + StringUtils.quoteAndEscape(
workingDirectory.getPath(), '"' ) );
+ }
+
public void testCommandLineWithStartVersionAndEndVersionEquals()
throws Exception
{
@@ -182,6 +190,19 @@ private void testCommandLine( String scmUrl, ScmBranch
branch, Date startDate, D
assertCommandLine( commandLine, workingDirectory, cl );
}
+ private void testCommandLine( String scmUrl, ScmBranch branch, ScmVersion
endVersion, String commandLine )
+ throws Exception
+ {
+ ScmRepository repository = getScmManager().makeScmRepository( scmUrl );
+
+ GitScmProviderRepository gitRepository = (GitScmProviderRepository)
repository.getProviderRepository();
+
+ Commandline cl = GitChangeLogCommand.createCommandLine( gitRepository,
workingDirectory, branch, null, null,
+ null, endVersion, null, true );
+
+ assertCommandLine( commandLine, workingDirectory, cl );
+ }
+
private void testCommandLine( String scmUrl, ScmBranch branch, ScmVersion
startVersion, ScmVersion endVersion, String commandLine )
throws Exception
{
diff --git
a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gittest/src/main/java/org/apache/maven/scm/provider/git/command/changelog/GitChangeLogCommandTckTest.java
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gittest/src/main/java/org/apache/maven/scm/provider/git/command/changelog/GitChangeLogCommandTckTest.java
index 0faa49681..14312441f 100644
---
a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gittest/src/main/java/org/apache/maven/scm/provider/git/command/changelog/GitChangeLogCommandTckTest.java
+++
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gittest/src/main/java/org/apache/maven/scm/provider/git/command/changelog/GitChangeLogCommandTckTest.java
@@ -20,6 +20,13 @@
*/
import org.apache.maven.scm.command.checkout.CheckOutScmResult;
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.ScmRevision;
+import org.apache.maven.scm.ScmTestCase;
+import org.apache.maven.scm.command.changelog.ChangeLogScmRequest;
+import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
+import org.apache.maven.scm.command.checkin.CheckInScmResult;
+import org.apache.maven.scm.provider.ScmProvider;
import org.apache.maven.scm.provider.git.GitScmTestUtils;
import org.apache.maven.scm.repository.ScmRepository;
import org.apache.maven.scm.tck.command.changelog.ChangeLogCommandTckTest;
@@ -52,4 +59,122 @@ protected CheckOutScmResult checkOut( File
workingDirectory, ScmRepository repos
GitScmTestUtils.setDefaultUser( workingDirectory );
}
}
+
+ public void testChangeLogCommandBetweenHeadAndPreviousCommit()
+ throws Exception
+ {
+ Thread.sleep( 1000 );
+ ScmRepository scmRepository = getScmRepository();
+ ScmProvider provider = getScmManager().getProviderByRepository(
scmRepository );
+ ScmFileSet fileSet = new ScmFileSet( getWorkingCopy() );
+
+ ChangeLogScmRequest clr = new ChangeLogScmRequest( scmRepository,
fileSet );
+ // We set only endRevision to HEAD
+ clr.setStartRevision( new ScmRevision( "HEAD~1" ) );
+ clr.setEndRevision( new ScmRevision( "HEAD" ) );
+
+ //Make a change to the readme.txt and commit the change
+ this.edit( getWorkingCopy(), "readme.txt", null, getScmRepository() );
+ ScmTestCase.makeFile( getWorkingCopy(), "/readme.txt", "changed
readme.txt" );
+ CheckInScmResult checkInResult = provider.checkIn( getScmRepository(),
fileSet, "dummy commit message" );
+ assertTrue( "Unable to checkin changes to the repository",
checkInResult.isSuccess() );
+
+ ChangeLogScmResult result = provider.changeLog( clr );
+ assertTrue( result.getProviderMessage(), result.isSuccess() );
+ assertEquals(
+ "the changelog from root does not have good commits number",
+ 1, result.getChangeLog().getChangeSets().size()
+ );
+ }
+
+ public void testChangeIsEmptyForVersionHeadToHead()
+ throws Exception
+ {
+ Thread.sleep( 1000 );
+ ScmRepository scmRepository = getScmRepository();
+ ScmProvider provider = getScmManager().getProviderByRepository(
scmRepository );
+ ScmFileSet fileSet = new ScmFileSet( getWorkingCopy() );
+
+ ChangeLogScmRequest clr = new ChangeLogScmRequest( scmRepository,
fileSet );
+ // We set only endRevision to HEAD
+ clr.setStartRevision( new ScmRevision( "HEAD" ) );
+ clr.setEndRevision( new ScmRevision( "HEAD" ) );
+
+ //Make a change to the readme.txt and commit the change
+ this.edit( getWorkingCopy(), "readme.txt", null, getScmRepository() );
+ ScmTestCase.makeFile( getWorkingCopy(), "/readme.txt", "changed
readme.txt" );
+ CheckInScmResult checkInResult = provider.checkIn( getScmRepository(),
fileSet, "dummy commit message" );
+ assertTrue( "Unable to checkin changes to the repository",
checkInResult.isSuccess() );
+
+ ChangeLogScmResult result = provider.changeLog( clr );
+ assertTrue( result.getProviderMessage(), result.isSuccess() );
+ assertEquals(
+ "the changelog from root does not have good commits number",
+ 0, result.getChangeLog().getChangeSets().size()
+ );
+ }
+
+
+ public void testChangeLogCommandWithOnlyEndVersion()
+ throws Exception
+ {
+ Thread.sleep( 1000 );
+ ScmRepository scmRepository = getScmRepository();
+ ScmProvider provider = getScmManager().getProviderByRepository(
scmRepository );
+ ScmFileSet fileSet = new ScmFileSet( getWorkingCopy() );
+
+ ChangeLogScmRequest clr = new ChangeLogScmRequest( scmRepository,
fileSet );
+
+ // We set only endRevision to HEAD
+ clr.setEndRevision( new ScmRevision( "HEAD" ) );
+ ChangeLogScmResult firstResult = provider.changeLog( clr );
+
+ int firstLogSize = firstResult.getChangeLog().getChangeSets().size();
+ assertEquals( "Unexpected initial log size", 0, firstLogSize );
+
+ Thread.sleep( 2000 );
+ //Make a change to the readme.txt and commit the change
+ this.edit( getWorkingCopy(), "readme.txt", null, getScmRepository() );
+ ScmTestCase.makeFile( getWorkingCopy(), "/readme.txt", "changed
readme.txt" );
+ CheckInScmResult checkInResult = provider.checkIn( getScmRepository(),
fileSet, "dummy commit message" );
+ assertTrue( "Unable to checkin changes to the repository",
checkInResult.isSuccess() );
+
+ ChangeLogScmResult secondResult = provider.changeLog( clr );
+ assertTrue( secondResult.getProviderMessage(),
secondResult.isSuccess() );
+ assertEquals(
+ "the changelog from root does not have good commits number",
+ 0, secondResult.getChangeLog().getChangeSets().size()
+ );
+ }
+
+ public void testChangeLogCommandFromRootToEnd()
+ throws Exception
+ {
+ Thread.sleep( 1000 );
+ ScmRepository scmRepository = getScmRepository();
+ ScmProvider provider = getScmManager().getProviderByRepository(
scmRepository );
+ ScmFileSet fileSet = new ScmFileSet( getWorkingCopy() );
+
+ ChangeLogScmRequest clr = new ChangeLogScmRequest( scmRepository,
fileSet );
+ clr.setFromStartOfRepository();
+ clr.setEndRevision( new ScmRevision( "HEAD" ) );
+ ChangeLogScmResult firstResult = provider.changeLog( clr );
+
+ int firstLogSize = firstResult.getChangeLog().getChangeSets().size();
+ assertEquals( "Unexpected initial log size", 1, firstLogSize );
+
+ Thread.sleep( 2000 );
+ //Make a change to the readme.txt and commit the change
+ this.edit( getWorkingCopy(), "readme.txt", null, getScmRepository() );
+ ScmTestCase.makeFile( getWorkingCopy(), "/readme.txt", "changed
readme.txt" );
+ CheckInScmResult checkInResult = provider.checkIn( getScmRepository(),
fileSet, "dummy commit message" );
+ assertTrue( "Unable to checkin changes to the repository",
checkInResult.isSuccess() );
+
+ ChangeLogScmResult secondResult = provider.changeLog( clr );
+ assertTrue( secondResult.getProviderMessage(),
secondResult.isSuccess() );
+ assertEquals(
+ "the changelog from root does not have good commits number",
+ 2, secondResult.getChangeLog().getChangeSets().size()
+ );
+ }
}
diff --git
a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/changelog/JGitChangeLogCommand.java
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/changelog/JGitChangeLogCommand.java
index a8fef0160..472998814 100644
---
a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/changelog/JGitChangeLogCommand.java
+++
b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/changelog/JGitChangeLogCommand.java
@@ -33,6 +33,7 @@
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
+import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevSort;
@@ -40,6 +41,7 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Date;
import java.util.List;
@@ -75,10 +77,30 @@ protected ChangeLogScmResult executeChangeLogCommand(
ScmProviderRepository repo
return executeChangeLogCommand( repo, fileSet, startDate, endDate,
branch, datePattern, null, null );
}
+ protected ChangeLogScmResult executeChangeLogCommand(
ScmProviderRepository repository, ScmFileSet fileSet,
+ ScmVersion
endVersion,
+ String datePattern,
boolean fromStartOfRepository )
+ throws ScmException
+ {
+ return executeChangeLogCommand( repository, fileSet, null, null, null,
datePattern, null, endVersion,
+ fromStartOfRepository );
+ }
+
protected ChangeLogScmResult executeChangeLogCommand(
ScmProviderRepository repo, ScmFileSet fileSet,
Date startDate, Date
endDate, ScmBranch branch,
String datePattern,
ScmVersion startVersion,
ScmVersion
endVersion )
+ throws ScmException
+ {
+ return executeChangeLogCommand(
+ repo, fileSet, startDate, endDate, branch, datePattern,
startVersion, endVersion, false
+ );
+ }
+
+ protected ChangeLogScmResult executeChangeLogCommand(
ScmProviderRepository repo, ScmFileSet fileSet,
+ Date startDate, Date
endDate, ScmBranch branch,
+ String datePattern,
ScmVersion startVersion,
+ ScmVersion
endVersion, boolean fromStartOfRepository )
throws ScmException
{
Git git = null;
@@ -89,8 +111,20 @@ protected ChangeLogScmResult executeChangeLogCommand(
ScmProviderRepository repo
String startRev = startVersion != null ? startVersion.getName() :
null;
String endRev = endVersion != null ? endVersion.getName() : null;
- List<ChangeEntry> gitChanges =
- this.whatchanged( git.getRepository(), null, startRev, endRev,
startDate, endDate, -1 );
+ if ( endRev != null && startRev == null && !fromStartOfRepository )
+ {
+ startRev = Constants.HEAD;
+ }
+
+ List<ChangeEntry> gitChanges = null;
+ if ( startRev != null && startRev.equals( endRev ) )
+ {
+ gitChanges = Collections.emptyList();
+ }
+ else
+ {
+ gitChanges = this.whatchanged( git.getRepository(), null,
startRev, endRev, startDate, endDate, -1 );
+ }
List<ChangeSet> modifications = new ArrayList<ChangeSet>(
gitChanges.size() );
@@ -127,6 +161,7 @@ protected ChangeLogScmResult executeChangeLogCommand(
ScmProviderRepository repo
Date fromDate, Date toDate, int
maxLines )
throws MissingObjectException, IncorrectObjectTypeException,
IOException
{
+
List<RevCommit> revs = JGitUtils.getRevCommits( repo, sortings,
fromRev, toRev, fromDate, toDate, maxLines );
List<ChangeEntry> changes = new ArrayList<ChangeEntry>( revs.size() );
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services