From 1e1b85270f93b3bca624c99b478f3a9a23be2395 Mon Sep 17 00:00:00 2001 From: James Moger Date: Sat, 29 Sep 2012 23:40:46 -0400 Subject: Preliminary implementation of server-side forking (issue 137) The fork mechanism clones the repository , access restrictions, and other config options. The app has been updated throughout to handle personal repositories and to properly display origin/fork links. In order to fork a repository the user account must have the #fork role, the origin repository must permit forking, and the user account must have standard clone permissions to the repository. Because forking introduces a new user role no existing user accounts can automatically begin forking a repository. This is both a pro and a con. Since the fork has the same access restrictions as the origin repository, those who can access the origin may also access the fork. This is intentional to facilitate integration-manager workflow. The fork owner does have the power to completely change the access restrictions of his/her fork. --- src/com/gitblit/utils/StringUtils.java | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'src/com/gitblit/utils/StringUtils.java') diff --git a/src/com/gitblit/utils/StringUtils.java b/src/com/gitblit/utils/StringUtils.java index e4407901..07113388 100644 --- a/src/com/gitblit/utils/StringUtils.java +++ b/src/com/gitblit/utils/StringUtils.java @@ -367,7 +367,7 @@ public class StringUtils { * @return the first invalid character found or null if string is acceptable */ public static Character findInvalidCharacter(String name) { - char[] validChars = { '/', '.', '_', '-' }; + char[] validChars = { '/', '.', '_', '-', '~' }; for (char c : name.toCharArray()) { if (!Character.isLetterOrDigit(c)) { boolean ok = false; @@ -660,4 +660,31 @@ public class StringUtils { } return input; } + + /** + * Returns the first path element of a path string. If no path separator is + * found in the path, an empty string is returned. + * + * @param path + * @return the first element in the path + */ + public static String getFirstPathElement(String path) { + if (path.indexOf('/') > -1) { + return path.substring(0, path.indexOf('/')).trim(); + } + return ""; + } + + /** + * Returns the last path element of a path string + * + * @param path + * @return the last element in the path + */ + public static String getLastPathElement(String path) { + if (path.indexOf('/') > -1) { + return path.substring(path.lastIndexOf('/') + 1); + } + return path; + } } \ No newline at end of file -- cgit v1.2.3