Commits

Sebastian Sdorra committed 9b56e12

implement disable last commit for mercurial browse command

  • Participants
  • Parent commits cd03e40

Comments (0)

Files changed (4)

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

       cmd.path(request.getPath());
     }
 
+    if (request.isDisableLastCommit())
+    {
+      cmd.disableLastCommit();
+    }
+
     BrowserResult result = new BrowserResult();
 
     result.setFiles(cmd.execute());

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

    *
    *
    * @return
+   */
+  public HgFileviewCommand disableLastCommit()
+  {
+    disableLastCommit = true;
+    cmdAppend("-d");
+
+    return this;
+  }
+
+  /**
+   * Method description
+   *
+   *
+   * @return
    *
    * @throws IOException
    */
     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;
   }
 
     return path;
   }
+
+  //~--- fields ---------------------------------------------------------------
+
+  /** Field description */
+  private boolean disableLastCommit = false;
 }

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

     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 = []
   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'),
   ])
 }

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

   @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());
     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;
+  }
 }