improve performance of mercurial log command

This commit is contained in:
Sebastian Sdorra
2012-07-04 10:33:11 +02:00
parent b9eb0aff5f
commit ebc3db753e
2 changed files with 99 additions and 41 deletions

View File

@@ -107,9 +107,14 @@ public class HgLogCommand extends AbstractCommand implements LogCommand
public ChangesetPagingResult getChangesets(LogCommandRequest request) public ChangesetPagingResult getChangesets(LogCommandRequest request)
throws IOException, RepositoryException throws IOException, RepositoryException
{ {
ChangesetPagingResult result = null;
com.aragost.javahg.Repository repository = open(); com.aragost.javahg.Repository repository = open();
HgLogChangesetCommand cmd = HgLogChangesetCommand.on(repository); HgLogChangesetCommand cmd = HgLogChangesetCommand.on(repository);
if (!Strings.isNullOrEmpty(request.getPath()))
{
String startChangeset = request.getStartChangeset(); String startChangeset = request.getStartChangeset();
String endChangeset = request.getEndChangeset(); String endChangeset = request.getEndChangeset();
@@ -127,16 +132,7 @@ public class HgLogCommand extends AbstractCommand implements LogCommand
cmd.rev(startChangeset.concat(":0")); cmd.rev(startChangeset.concat(":0"));
} }
List<Changeset> changesetList = null; List<Changeset> changesetList = cmd.execute(request.getPath());
if (!Strings.isNullOrEmpty(request.getPath()))
{
changesetList = cmd.execute(request.getPath());
}
else
{
changesetList = cmd.execute();
}
int start = request.getPagingStart(); int start = request.getPagingStart();
int limit = request.getPagingLimit(); int limit = request.getPagingLimit();
@@ -160,6 +156,55 @@ public class HgLogCommand extends AbstractCommand implements LogCommand
changesets = Lists.newArrayList(sublist); changesets = Lists.newArrayList(sublist);
} }
return new ChangesetPagingResult(changesetList.size(), changesets); result = new ChangesetPagingResult(changesetList.size(), changesets);
}
else
{
int start = -1;
int end = 0;
String startChangeset = request.getStartChangeset();
String endChangeset = request.getEndChangeset();
if (!Strings.isNullOrEmpty(startChangeset))
{
start = HgLogChangesetCommand.on(repository).rev(
startChangeset).singleRevision();
}
else if (!Strings.isNullOrEmpty(endChangeset))
{
end = HgLogChangesetCommand.on(repository).rev(
endChangeset).singleRevision();
}
if (start < 0)
{
start =
HgLogChangesetCommand.on(repository).rev("tip").singleRevision();
}
int total = start - end + 1;
if (request.getPagingStart() > 0)
{
start -= request.getPagingStart();
}
if (request.getPagingLimit() > 0)
{
end = start - request.getPagingLimit() + 1;
}
if ( end < 0 ){
end = 0;
}
List<Changeset> changesets = cmd.rev(start + ":" + end).execute();
result = new ChangesetPagingResult(total, changesets);
}
return result;
} }
} }

View File

@@ -191,6 +191,19 @@ public class HgLogChangesetCommand extends AbstractCommand
return Utils.single(execute(files)); return Utils.single(execute(files));
} }
/**
* Method description
*
*
* @param files
*
* @return
*/
public int singleRevision(String... files)
{
return Utils.single(loadRevisions(files));
}
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------
/** /**