implement mercurial getChangeset with path method

This commit is contained in:
Sebastian Sdorra
2011-11-14 16:03:51 +01:00
parent 5ff544a2a5
commit cd44c8b3b9
2 changed files with 118 additions and 52 deletions

View File

@@ -110,21 +110,38 @@ public class HgChangesetViewer extends AbstractHgHandler
public ChangesetPagingResult getChangesets(int start, int max) public ChangesetPagingResult getChangesets(int start, int max)
throws IOException, RepositoryException throws IOException, RepositoryException
{ {
return getChangesets(String.valueOf(start), String.valueOf(max), null, return getChangesets(null, null, String.valueOf(start),
null); String.valueOf(max), null, null);
}
@Override
public ChangesetPagingResult getChangesets(String path, int start, int max)
throws IOException, RepositoryException {
// TODO Auto-generated method stub
return null;
} }
/** /**
* Method description * Method description
* *
* *
* @param path
* @param start
* @param max
*
* @return
*
* @throws IOException
* @throws RepositoryException
*/
@Override
public ChangesetPagingResult getChangesets(String path, int start, int max)
throws IOException, RepositoryException
{
return getChangesets(path, null, String.valueOf(start),
String.valueOf(max), null, null);
}
/**
* Method description
*
*
*
* @param path
* @param revision
* @param pageStart * @param pageStart
* @param pageLimit * @param pageLimit
* @param revisionStart * @param revisionStart
@@ -135,12 +152,15 @@ public class HgChangesetViewer extends AbstractHgHandler
* @throws IOException * @throws IOException
* @throws RepositoryException * @throws RepositoryException
*/ */
public ChangesetPagingResult getChangesets(String pageStart, public ChangesetPagingResult getChangesets(String path, String revision,
String pageLimit, String revisionStart, String revisionEnd) String pageStart, String pageLimit, String revisionStart,
String revisionEnd)
throws IOException, RepositoryException throws IOException, RepositoryException
{ {
Map<String, String> env = new HashMap<String, String>(); Map<String, String> env = new HashMap<String, String>();
env.put(ENV_PATH, Util.nonNull(path));
env.put(ENV_REVISION, Util.nonNull(revision));
env.put(ENV_PAGE_START, Util.nonNull(pageStart)); env.put(ENV_PAGE_START, Util.nonNull(pageStart));
env.put(ENV_PAGE_LIMIT, Util.nonNull(pageLimit)); env.put(ENV_PAGE_LIMIT, Util.nonNull(pageLimit));
env.put(ENV_REVISION_START, Util.nonNull(revisionStart)); env.put(ENV_REVISION_START, Util.nonNull(revisionStart));
@@ -164,6 +184,6 @@ public class HgChangesetViewer extends AbstractHgHandler
public ChangesetPagingResult getChangesets(String startNode, String endNode) public ChangesetPagingResult getChangesets(String startNode, String endNode)
throws IOException, RepositoryException throws IOException, RepositoryException
{ {
return getChangesets(null, null, startNode, endNode); return getChangesets(null, null, null, null, startNode, endNode);
} }
} }

View File

@@ -29,8 +29,10 @@
# #
# #
# import basic packages
import sys, os import sys, os
# create python path
pythonPath = os.environ['SCM_PYTHON_PATH'] pythonPath = os.environ['SCM_PYTHON_PATH']
if len(pythonPath) > 0: if len(pythonPath) > 0:
@@ -38,49 +40,21 @@ if len(pythonPath) > 0:
for i in range(len(pathParts)): for i in range(len(pathParts)):
sys.path.insert(i, pathParts[i]) sys.path.insert(i, pathParts[i])
# import mercurial packages
from mercurial import hg, ui, commands from mercurial import hg, ui, commands
from mercurial.node import hex from mercurial.node import hex
from xml.sax.saxutils import escape from xml.sax.saxutils import escape
import datetime, time import datetime, time
repositoryPath = os.environ['SCM_REPOSITORY_PATH']
repo = hg.repository(ui.ui(), path = repositoryPath)
startNode = os.environ['SCM_REVISION_START']
endNode = os.environ['SCM_REVISION_END']
total = len(repo)
if len(startNode) > 0 and len(endNode) > 0:
# start and end revision
startRev = repo[startNode].rev() -1
endRev = repo[endNode].rev()
else:
# paging
start = os.environ['SCM_PAGE_START']
limit = os.environ['SCM_PAGE_LIMIT']
limit = int(limit)
end = int(start)
endRev = total - end - 1
startRev = endRev - limit
# fix negative start revisions
if startRev < -1:
startRev = -1
# header # header
def printHeader(total):
print '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' print '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
print '<changeset-paging>' print '<changeset-paging>'
print ' <total>' + str(total) + '</total>' print ' <total>' + str(total) + '</total>'
print ' <changesets>' print ' <changesets>'
# changesets # changeset
for i in range(endRev, startRev, -1): def printChangeset(repo, ctx):
ctx = repo[i]
time = int(ctx.date()[0]) * 1000 time = int(ctx.date()[0]) * 1000
branch = ctx.branch() branch = ctx.branch()
tags = ctx.tags() tags = ctx.tags()
@@ -99,7 +73,7 @@ for i in range(endRev, startRev, -1):
authorName = authorName[0:s].strip() authorName = authorName[0:s].strip()
print ' <changeset>' print ' <changeset>'
print ' <id>' + str(i) + ':' + hex(ctx.node()[:6]) + '</id>' print ' <id>' + str(ctx.rev()) + ':' + hex(ctx.node()[:6]) + '</id>'
print ' <author>' + escape(ctx.user()) + '</author>' print ' <author>' + escape(ctx.user()) + '</author>'
print ' <description>' + escape(ctx.description()) + '</description>' print ' <description>' + escape(ctx.description()) + '</description>'
print ' <date>' + str(time).split('.')[0] + '</date>' print ' <date>' + str(time).split('.')[0] + '</date>'
@@ -149,5 +123,77 @@ for i in range(endRev, startRev, -1):
print ' </changeset>' print ' </changeset>'
# footer # footer
def printFooter():
print ' </changesets>' print ' </changesets>'
print '</changeset-paging>' print '</changeset-paging>'
def printChangesetsForPath(repo, path):
rev = os.environ['SCM_REVISION']
if len(rev) <= 0:
rev = "tip"
fctxs = repo[rev].filectx(path)
revs = []
for i in fctxs.filelog():
fctx = fctxs.filectx(i)
revs.append(fctx.changectx())
# reverse changesets
revs.reverse()
total = len(revs)
# handle paging
start = os.environ['SCM_PAGE_START']
limit = os.environ['SCM_PAGE_LIMIT']
if len(start) > 0:
revs = revs[int(start):]
if len(limit) > 0:
revs = revs[:int(limit)]
# output
printHeader(total)
for ctx in revs:
printChangeset(repo, ctx)
printFooter()
def printChangesetsForStartAndEnd(repo, startRev, endRev):
printHeader(len(repo))
for i in range(endRev, startRev, -1):
printChangeset(repo, repo[i])
printFooter()
repositoryPath = os.environ['SCM_REPOSITORY_PATH']
repo = hg.repository(ui.ui(), path = repositoryPath)
path = os.environ['SCM_PATH']
startNode = os.environ['SCM_REVISION_START']
endNode = os.environ['SCM_REVISION_END']
if len(path) > 0:
printChangesetsForPath(repo, path)
else:
if len(startNode) > 0 and len(endNode) > 0:
# start and end revision
startRev = repo[startNode].rev() -1
endRev = repo[endNode].rev()
else:
# paging
start = os.environ['SCM_PAGE_START']
limit = os.environ['SCM_PAGE_LIMIT']
limit = int(limit)
end = int(start)
endRev = len(repo) - end - 1
startRev = endRev - limit
# fix negative start revisions
if startRev < -1:
startRev = -1
# print
printChangesetsForStartAndEnd(repo, startRev, endRev)