enhance logcommand

This commit is contained in:
Eduard Heimbuch
2019-10-25 12:31:18 +02:00
parent 5c7bd90f7a
commit a938fd8682
8 changed files with 42 additions and 10 deletions

View File

@@ -178,7 +178,7 @@ public final class LogCommandBuilder
logger.debug("get changeset for {} with disabled cache", id); logger.debug("get changeset for {} with disabled cache", id);
} }
changeset = logCommand.getChangeset(id); changeset = logCommand.getChangeset(id, request);
} }
else else
{ {
@@ -192,7 +192,7 @@ public final class LogCommandBuilder
logger.debug("get changeset for {}", id); logger.debug("get changeset for {}", id);
} }
changeset = logCommand.getChangeset(id); changeset = logCommand.getChangeset(id, request);
if (changeset != null) if (changeset != null)
{ {

View File

@@ -49,7 +49,7 @@ import java.io.IOException;
*/ */
public interface LogCommand { public interface LogCommand {
Changeset getChangeset(String id) throws IOException; Changeset getChangeset(String id, LogCommandRequest request) throws IOException;
ChangesetPagingResult getChangesets(LogCommandRequest request) throws IOException; ChangesetPagingResult getChangesets(LogCommandRequest request) throws IOException;
} }

View File

@@ -106,7 +106,7 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
* @return * @return
*/ */
@Override @Override
public Changeset getChangeset(String revision) public Changeset getChangeset(String revision, LogCommandRequest request)
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
@@ -131,7 +131,13 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
if (commit != null) if (commit != null)
{ {
converter = new GitChangesetConverter(gr, revWalk); converter = new GitChangesetConverter(gr, revWalk);
changeset = converter.createChangeset(commit);
if (request != null && !Strings.isNullOrEmpty(request.getBranch())) {
changeset = converter.createChangeset(commit, request.getBranch());
} else {
changeset = converter.createChangeset(commit);
}
} }
else if (logger.isWarnEnabled()) else if (logger.isWarnEnabled())
{ {

View File

@@ -171,7 +171,33 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
public void testGetCommit() public void testGetCommit()
{ {
GitLogCommand command = createCommand(); GitLogCommand command = createCommand();
Changeset c = command.getChangeset("435df2f061add3589cb3"); Changeset c = command.getChangeset("435df2f061add3589cb3", null);
assertNotNull(c);
String revision = "435df2f061add3589cb326cc64be9b9c3897ceca";
assertEquals(revision, c.getId());
assertEquals("added a and b files", c.getDescription());
checkDate(c.getDate());
assertEquals("Douglas Adams", c.getAuthor().getName());
assertEquals("douglas.adams@hitchhiker.com", c.getAuthor().getMail());
assertEquals("added a and b files", c.getDescription());
GitModificationsCommand gitModificationsCommand = new GitModificationsCommand(createContext(), repository);
Modifications modifications = gitModificationsCommand.getModifications(revision);
assertNotNull(modifications);
assertTrue("modified list should be empty", modifications.getModified().isEmpty());
assertTrue("removed list should be empty", modifications.getRemoved().isEmpty());
assertFalse("added list should not be empty", modifications.getAdded().isEmpty());
assertEquals(2, modifications.getAdded().size());
assertThat(modifications.getAdded(), contains("a.txt", "b.txt"));
}
@Test
public void testGetCommitWithBranch()
{
GitLogCommand command = createCommand();
Changeset c = command.getChangeset("435df2f061add3589cb3", null);
assertNotNull(c); assertNotNull(c);
String revision = "435df2f061add3589cb326cc64be9b9c3897ceca"; String revision = "435df2f061add3589cb326cc64be9b9c3897ceca";

View File

@@ -68,7 +68,7 @@ public class HgLogCommand extends AbstractCommand implements LogCommand
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------
@Override @Override
public Changeset getChangeset(String id) { public Changeset getChangeset(String id, LogCommandRequest request) {
com.aragost.javahg.Repository repository = open(); com.aragost.javahg.Repository repository = open();
HgLogChangesetCommand cmd = on(repository); HgLogChangesetCommand cmd = on(repository);

View File

@@ -154,7 +154,7 @@ public class HgLogCommandTest extends AbstractHgCommandTestBase
HgLogCommand command = createComamnd(); HgLogCommand command = createComamnd();
String revision = "a9bacaf1b7fa0cebfca71fed4e59ed69a6319427"; String revision = "a9bacaf1b7fa0cebfca71fed4e59ed69a6319427";
Changeset c = Changeset c =
command.getChangeset(revision); command.getChangeset(revision, null);
assertNotNull(c); assertNotNull(c);
assertEquals(revision, c.getId()); assertEquals(revision, c.getId());

View File

@@ -75,7 +75,7 @@ public class SvnLogCommand extends AbstractSvnCommand implements LogCommand
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Changeset getChangeset(String revision) { public Changeset getChangeset(String revision, LogCommandRequest request) {
Changeset changeset = null; Changeset changeset = null;
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())

View File

@@ -128,7 +128,7 @@ public class SvnLogCommandTest extends AbstractSvnCommandTestBase
@Test @Test
public void testGetCommit() { public void testGetCommit() {
Changeset c = createCommand().getChangeset("3"); Changeset c = createCommand().getChangeset("3", null);
assertNotNull(c); assertNotNull(c);
assertEquals("3", c.getId()); assertEquals("3", c.getId());