implement recursive option for mercurial browse command

This commit is contained in:
Sebastian Sdorra
2013-01-19 13:22:27 +01:00
parent 9953a84567
commit d34ce7b0c9
4 changed files with 63 additions and 14 deletions

View File

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

View File

@@ -157,6 +157,19 @@ public class HgFileviewCommand extends AbstractCommand
return this; return this;
} }
/**
* Method description
*
*
* @return
*/
public HgFileviewCommand recursive()
{
cmdAppend("-c");
return this;
}
/** /**
* Method description * Method description
* *

View File

@@ -48,7 +48,7 @@ def appendTrailingSlash(path):
path += '/' path += '/'
return path return path
def collectFiles(revCtx, path, files, directories): def collectFiles(revCtx, path, files, directories, recursive):
length = 0 length = 0
paths = [] paths = []
mf = revCtx.manifest() mf = revCtx.manifest()
@@ -66,6 +66,7 @@ def collectFiles(revCtx, path, files, directories):
if f.startswith(directory): if f.startswith(directory):
paths.append(f) paths.append(f)
if not recursive:
for p in paths: for p in paths:
parts = p.split('/') parts = p.split('/')
depth = len(parts) depth = len(parts)
@@ -78,6 +79,9 @@ def collectFiles(revCtx, path, files, directories):
dirpath += parts[i] + '/' dirpath += parts[i] + '/'
if not dirpath in directories: if not dirpath in directories:
directories.append(dirpath) directories.append(dirpath)
else:
for p in paths:
files.append(revCtx[p])
def createSubRepositoryMap(revCtx): def createSubRepositoryMap(revCtx):
subrepos = {} subrepos = {}
@@ -140,7 +144,7 @@ def fileview(ui, repo, **opts):
if path.endswith('/'): if path.endswith('/'):
path = path[0:-1] path = path[0:-1]
transport = opts['transport'] transport = opts['transport']
collectFiles(revCtx, path, files, directories) collectFiles(revCtx, path, files, directories, opts['recursive'])
subRepositories = createSubRepositoryMap(revCtx) subRepositories = createSubRepositoryMap(revCtx)
for k, v in subRepositories.iteritems(): for k, v in subRepositories.iteritems():
if k.startswith(path): if k.startswith(path):
@@ -155,6 +159,7 @@ cmdtable = {
'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'),
('c', 'recursive', False, 'browse repository recursive'),
('d', 'disableLastCommit', False, 'disables last commit description and date'), ('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

@@ -159,6 +159,32 @@ public class HgBrowseCommandTest extends AbstractHgCommandTestBase
assertNull(a.getLastModified()); assertNull(a.getLastModified());
} }
/**
* Method description
*
*
* @throws IOException
* @throws RepositoryException
*/
@Test
public void testRecursive() throws IOException, RepositoryException
{
BrowseCommandRequest request = new BrowseCommandRequest();
request.setRecursive(true);
BrowserResult result = new HgBrowseCommand(cmdContext,
repository).getBrowserResult(request);
assertNotNull(result);
List<FileObject> foList = result.getFiles();
assertNotNull(foList);
assertFalse(foList.isEmpty());
assertEquals(5, foList.size());
}
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------
/** /**