Exemplo n.º 1
0
 private GitilesView.Builder parseShowCommand(String repoName, RevisionParser.Result result) {
   if (result == null || result.getOldRevision() != null) {
     return null;
   }
   if (result.getPath().isEmpty()) {
     return GitilesView.revision().setRepositoryName(repoName).setRevision(result.getRevision());
   }
   return GitilesView.path()
       .setRepositoryName(repoName)
       .setRevision(result.getRevision())
       .setPathPart(result.getPath());
 }
Exemplo n.º 2
0
 private GitilesView.Builder parseDiffCommand(String repoName, RevisionParser.Result result) {
   if (result == null) {
     return null;
   }
   return GitilesView.diff()
       .setRepositoryName(repoName)
       .setRevision(result.getRevision())
       .setOldRevision(result.getOldRevision())
       .setPathPart(result.getPath());
 }
Exemplo n.º 3
0
 private GitilesView.Builder parseDocCommand(String repoName, RevisionParser.Result result) {
   if (result == null || result.getOldRevision() != null) {
     return null;
   }
   GitilesView.Builder b =
       GitilesView.doc().setRepositoryName(repoName).setRevision(result.getRevision());
   if (!result.getPath().isEmpty()) {
     b.setPathPart(result.getPath());
   }
   return b;
 }
Exemplo n.º 4
0
 private GitilesView.Builder parseBlameCommand(
     HttpServletRequest req, String repoName, String path) throws IOException {
   if (path.isEmpty()) {
     return null;
   }
   RevisionParser.Result result = parseRevision(req, path);
   if (result == null || result.getOldRevision() != null || result.getPath().isEmpty()) {
     return null;
   }
   return GitilesView.blame()
       .setRepositoryName(repoName)
       .setRevision(result.getRevision())
       .setPathPart(result.getPath());
 }
Exemplo n.º 5
0
 private GitilesView.Builder parseAutoCommand(HttpServletRequest req, String repoName, String path)
     throws IOException {
   // Note: if you change the mapping for +, make sure to change
   // GitilesView.toUrl() correspondingly.
   if (path.isEmpty()) {
     return null;
   }
   RevisionParser.Result result = parseRevision(req, path);
   if (result == null) {
     return null;
   }
   if (result.getOldRevision() != null) {
     return parseDiffCommand(repoName, result);
   }
   GitilesView.Builder b = parseShowCommand(repoName, result);
   if (b != null && b.getPathPart() != null && b.getPathPart().endsWith(".md")) {
     return GitilesView.doc()
         .setRepositoryName(repoName)
         .setRevision(result.getRevision())
         .setPathPart(result.getPath());
   }
   return b;
 }
Exemplo n.º 6
0
 private GitilesView.Builder parseArchiveCommand(
     HttpServletRequest req, String repoName, String path) throws IOException {
   String ext = null;
   for (String e : ArchiveFormat.allExtensions()) {
     if (path.endsWith(e)) {
       path = path.substring(0, path.length() - e.length());
       ext = e;
       break;
     }
   }
   if (ext == null || path.endsWith("/")) {
     return null;
   }
   RevisionParser.Result result = parseRevision(req, path);
   if (result == null || result.getOldRevision() != null) {
     return null;
   }
   return GitilesView.archive()
       .setRepositoryName(repoName)
       .setRevision(result.getRevision())
       .setPathPart(Strings.emptyToNull(result.getPath()))
       .setExtension(ext);
 }