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()); cmd.path(request.getPath());
} }
if (request.isDisableLastCommit())
{
cmd.disableLastCommit();
}
BrowserResult result = new BrowserResult(); BrowserResult result = new BrowserResult();
result.setFiles(cmd.execute()); result.setFiles(cmd.execute());

View File

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

View File

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

View File

@@ -66,41 +66,16 @@ public class HgBrowseCommandTest extends AbstractHgCommandTestBase
@Test @Test
public void testBrowse() throws IOException, RepositoryException public void testBrowse() throws IOException, RepositoryException
{ {
BrowserResult result = List<FileObject> foList = getRootFromTip(new BrowseCommandRequest());
new HgBrowseCommand(cmdContext, FileObject a = getFileObject(foList, "a.txt");
repository).getBrowserResult(new BrowseCommandRequest()); 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()); assertFalse(a.isDirectory());
assertEquals("a.txt", a.getName()); assertEquals("a.txt", a.getName());
assertEquals("a.txt", a.getPath()); assertEquals("a.txt", a.getPath());
assertEquals("added new line for blame", a.getDescription()); assertEquals("added new line for blame", a.getDescription());
assertTrue(a.getLength() > 0); assertTrue(a.getLength() > 0);
checkDate(a.getLastModified()); checkDate(a.getLastModified());
assertNotNull(c);
assertTrue(c.isDirectory()); assertTrue(c.isDirectory());
assertEquals("c", c.getName()); assertEquals("c", c.getName());
assertEquals("c", c.getPath()); assertEquals("c", c.getPath());
@@ -161,4 +136,84 @@ public class HgBrowseCommandTest extends AbstractHgCommandTestBase
assertTrue(e.getLength() > 0); assertTrue(e.getLength() > 0);
checkDate(e.getLastModified()); 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;
}
} }