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();
}
if (request.isRecursive())
{
cmd.recursive();
}
BrowserResult result = new BrowserResult();
result.setFiles(cmd.execute());

View File

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

View File

@@ -48,7 +48,7 @@ def appendTrailingSlash(path):
path += '/'
return path
def collectFiles(revCtx, path, files, directories):
def collectFiles(revCtx, path, files, directories, recursive):
length = 0
paths = []
mf = revCtx.manifest()
@@ -66,18 +66,22 @@ def collectFiles(revCtx, path, files, directories):
if f.startswith(directory):
paths.append(f)
for p in paths:
parts = p.split('/')
depth = len(parts)
if depth is length:
file = revCtx[p]
files.append(file)
elif depth > length:
dirpath = ''
for i in range(0, length):
dirpath += parts[i] + '/'
if not dirpath in directories:
directories.append(dirpath)
if not recursive:
for p in paths:
parts = p.split('/')
depth = len(parts)
if depth is length:
file = revCtx[p]
files.append(file)
elif depth > length:
dirpath = ''
for i in range(0, length):
dirpath += parts[i] + '/'
if not dirpath in directories:
directories.append(dirpath)
else:
for p in paths:
files.append(revCtx[p])
def createSubRepositoryMap(revCtx):
subrepos = {}
@@ -140,7 +144,7 @@ def fileview(ui, repo, **opts):
if path.endswith('/'):
path = path[0:-1]
transport = opts['transport']
collectFiles(revCtx, path, files, directories)
collectFiles(revCtx, path, files, directories, opts['recursive'])
subRepositories = createSubRepositoryMap(revCtx)
for k, v in subRepositories.iteritems():
if k.startswith(path):
@@ -155,6 +159,7 @@ cmdtable = {
'fileview': (fileview,[
('r', 'revision', 'tip', 'revision to print'),
('p', 'path', '', 'path to print'),
('c', 'recursive', False, 'browse repository recursive'),
('d', 'disableLastCommit', False, 'disables last commit description and date'),
('t', 'transport', False, 'format the output for command server'),
])

View File

@@ -159,6 +159,32 @@ public class HgBrowseCommandTest extends AbstractHgCommandTestBase
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 ----------------------------------------------------------
/**