implement disable last commit for mercurial browse command

This commit is contained in:
Sebastian Sdorra
2013-01-18 21:11:25 +01:00
parent e8ebf7091d
commit da52e76ac7
4 changed files with 123 additions and 35 deletions

View File

@@ -94,6 +94,11 @@ public class HgBrowseCommand extends AbstractCommand implements BrowseCommand
cmd.path(request.getPath());
}
if (request.isDisableLastCommit())
{
cmd.disableLastCommit();
}
BrowserResult result = new BrowserResult();
result.setFiles(cmd.execute());

View File

@@ -85,6 +85,20 @@ public class HgFileviewCommand extends AbstractCommand
return new HgFileviewCommand(repository);
}
/**
* Method description
*
*
* @return
*/
public HgFileviewCommand disableLastCommit()
{
disableLastCommit = true;
cmdAppend("-d");
return this;
}
/**
* Method description
*
@@ -217,9 +231,13 @@ public class HgFileviewCommand extends AbstractCommand
file.setLength(stream.decimalIntUpTo(' '));
DateTime timestamp = stream.dateTimeUpTo(' ');
String description = stream.textUpTo('\0');
file.setLastModified(timestamp.getDate().getTime());
file.setDescription(stream.textUpTo('\0'));
if (!disableLastCommit)
{
file.setLastModified(timestamp.getDate().getTime());
file.setDescription(description);
}
return file;
}
@@ -297,4 +315,9 @@ public class HgFileviewCommand extends AbstractCommand
return path;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private boolean disableLastCommit = false;
}

View File

@@ -117,13 +117,17 @@ def printDirectory(ui, path, transport):
format = 'd%s\0'
ui.write( format % path)
def printFile(ui, repo, file, transport):
linkrev = repo[file.linkrev()]
date = "%d %d" % util.parsedate(linkrev.date())
def printFile(ui, repo, file, disableLastCommit, transport):
date = '0 0'
description = 'n/a'
if not disableLastCommit:
linkrev = repo[file.linkrev()]
date = '%d %d' % util.parsedate(linkrev.date())
description = linkrev.description()
format = '%s %i %s %s\n'
if transport:
format = 'f%s\n%i %s %s\0'
ui.write( format % (file.path(), file.size(), date, linkrev.description()))
ui.write( format % (file.path(), file.size(), date, description) )
def fileview(ui, repo, **opts):
files = []
@@ -144,13 +148,14 @@ def fileview(ui, repo, **opts):
for d in directories:
printDirectory(ui, d, transport)
for f in files:
printFile(ui, repo, f, transport)
printFile(ui, repo, f, opts['disableLastCommit'], transport)
cmdtable = {
# cmd name function call
'fileview': (fileview,[
('r', 'revision', 'tip', 'revision to print'),
('p', 'path', '', 'path to print'),
('d', 'disableLastCommit', False, 'disables last commit description and date'),
('t', 'transport', False, 'format the output for command server'),
])
}

View File

@@ -66,41 +66,16 @@ public class HgBrowseCommandTest extends AbstractHgCommandTestBase
@Test
public void testBrowse() throws IOException, RepositoryException
{
BrowserResult result =
new HgBrowseCommand(cmdContext,
repository).getBrowserResult(new BrowseCommandRequest());
List<FileObject> foList = getRootFromTip(new BrowseCommandRequest());
FileObject a = getFileObject(foList, "a.txt");
FileObject c = getFileObject(foList, "c");
assertNotNull(result);
List<FileObject> foList = result.getFiles();
assertNotNull(foList);
assertFalse(foList.isEmpty());
assertEquals(4, foList.size());
FileObject a = null;
FileObject c = null;
for (FileObject f : foList)
{
if ("a.txt".equals(f.getName()))
{
a = f;
}
else if ("c".equals(f.getName()))
{
c = f;
}
}
assertNotNull(a);
assertFalse(a.isDirectory());
assertEquals("a.txt", a.getName());
assertEquals("a.txt", a.getPath());
assertEquals("added new line for blame", a.getDescription());
assertTrue(a.getLength() > 0);
checkDate(a.getLastModified());
assertNotNull(c);
assertTrue(c.isDirectory());
assertEquals("c", c.getName());
assertEquals("c", c.getPath());
@@ -161,4 +136,84 @@ public class HgBrowseCommandTest extends AbstractHgCommandTestBase
assertTrue(e.getLength() > 0);
checkDate(e.getLastModified());
}
/**
* Method description
*
*
* @throws IOException
* @throws RepositoryException
*/
@Test
public void testDisableLastCommit() throws IOException, RepositoryException
{
BrowseCommandRequest request = new BrowseCommandRequest();
request.setDisableLastCommit(true);
List<FileObject> foList = getRootFromTip(request);
FileObject a = getFileObject(foList, "a.txt");
assertNull(a.getDescription());
assertNull(a.getLastModified());
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param foList
* @param name
*
* @return
*/
private FileObject getFileObject(List<FileObject> foList, String name)
{
FileObject a = null;
for (FileObject f : foList)
{
if (name.equals(f.getName()))
{
a = f;
break;
}
}
assertNotNull(a);
return a;
}
/**
* Method description
*
*
* @param request
*
* @return
*
* @throws IOException
* @throws RepositoryException
*/
private List<FileObject> getRootFromTip(BrowseCommandRequest request)
throws IOException, RepositoryException
{
BrowserResult result = new HgBrowseCommand(cmdContext,
repository).getBrowserResult(request);
assertNotNull(result);
List<FileObject> foList = result.getFiles();
assertNotNull(foList);
assertFalse(foList.isEmpty());
assertEquals(4, foList.size());
return foList;
}
}