Move duplicate code to strip .git suffix to a utility class

Code to strip the .git suffix off project names is duplicated in
a couple of places.

Implement this code in a common utility method.

Note that we cannot use this utility method in client UI code
because it imports Jgit constants that are not allowed in GWT
according to ee720b8ab7

Change-Id: I5e52e16d6f87aca22181e0fe0220a68635e6d789
This commit is contained in:
David Pursehouse
2013-02-13 16:51:38 +09:00
committed by Edwin Kempin
parent a73579c652
commit 65688b6c8f
3 changed files with 41 additions and 27 deletions

View File

@@ -14,13 +14,13 @@
package com.google.gerrit.server.args4j;
import com.google.gerrit.common.ProjectUtil;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.gerrit.server.project.ProjectControl;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import org.eclipse.jgit.lib.Constants;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.OptionDef;
@@ -58,18 +58,7 @@ public class ProjectControlHandler extends OptionHandler<ProjectControl> {
projectName = projectName.substring(1);
}
String nameWithoutSuffix = projectName;
if (nameWithoutSuffix.endsWith(Constants.DOT_GIT_EXT)) {
// Be nice and drop the trailing ".git" suffix, which we never keep
// in our database, but clients might mistakenly provide anyway.
//
nameWithoutSuffix = nameWithoutSuffix.substring(0, //
nameWithoutSuffix.length() - Constants.DOT_GIT_EXT.length());
while (nameWithoutSuffix.endsWith("/")) {
nameWithoutSuffix =
nameWithoutSuffix.substring(0, nameWithoutSuffix.length() - 1);
}
}
String nameWithoutSuffix = ProjectUtil.stripGitSuffix(projectName);
final ProjectControl control;
try {