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:

committed by
Edwin Kempin

parent
a73579c652
commit
65688b6c8f
@@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.common;
|
||||
|
||||
import org.eclipse.jgit.lib.Constants;
|
||||
|
||||
public class ProjectUtil {
|
||||
public static String stripGitSuffix(String name) {
|
||||
String nameWithoutSuffix = name;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
return nameWithoutSuffix;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user