Commits

Sebastian Sdorra  committed 2c5a4f4

implement recursive option for mercurial browse command

  • Participants
  • Parent commits cdcab7a

Comments (0)

Files changed (4)

File scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgBrowseCommand.java

       cmd.disableLastCommit();
     }
 
+    if (request.isRecursive())
+    {
+      cmd.recursive();
+    }
+
     BrowserResult result = new BrowserResult();
 
     result.setFiles(cmd.execute());

File scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/javahg/HgFileviewCommand.java

    * Method description
    *
    *
+   * @return
+   */
+  public HgFileviewCommand recursive()
+  {
+    cmdAppend("-c");
+
+    return this;
+  }
+
+  /**
+   * Method description
+   *
+   *
    * @param revision
    *
    * @return

File scm-plugins/scm-hg-plugin/src/main/resources/sonia/scm/hg/ext/fileview.py

     path += '/'
   return path
 
-def collectFiles(revCtx, path, files, directories):
+def collectFiles(revCtx, path, files, directories, recursive):
   length = 0
   paths = []
   mf = revCtx.manifest()
       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 = {}
   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):
   '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'),
   ])

File scm-plugins/scm-hg-plugin/src/test/java/sonia/scm/repository/spi/HgBrowseCommandTest.java

     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 ----------------------------------------------------------
 
   /**