URIish: Allow multiple slashes in paths

It's also allowed by C Git.

Change-Id: Ie0a0d1f57d84e70fd5ef50b7844d22fea43d0e08
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java
index 2202a91..8c7c992 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java
@@ -2,6 +2,7 @@
  * Copyright (C) 2009, Mykola Nikishov <mn@mn.com.ua>
  * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
  * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
+ * Copyright (C) 2013, Robin Stocker <robin@nibor.org>
  * and other copyright owners as documented in the project's IP log.
  *
  * This program and the accompanying materials are made available
@@ -611,7 +612,7 @@ public void testGetWithSlashDotGitHumanishName() throws URISyntaxException {
 
 	@Test
 	public void testGetTwoSlashesDotGitHumanishName() throws URISyntaxException {
-		assertEquals("", new URIish("/.git").getHumanishName());
+		assertEquals("", new URIish("//.git").getHumanishName());
 	}
 
 	@Test
@@ -646,7 +647,7 @@ public void testGetSlashValidSlashDotGitSlashHumanishName()
 	@Test
 	public void testGetSlashSlashDotGitSlashHumanishName()
 			throws IllegalArgumentException, URISyntaxException {
-		final String humanishName = new URIish(GIT_SCHEME + "/abc//.git")
+		final String humanishName = new URIish(GIT_SCHEME + "/.git")
 				.getHumanishName();
 		assertEquals("may return an empty humanish name", "", humanishName);
 	}
@@ -703,6 +704,21 @@ public void testGetValidWithSlashesDotGitSlashHumanishName()
 	}
 
 	@Test
+	public void testGetValidLocalWithTwoSlashesHumanishName()
+			throws IllegalArgumentException, URISyntaxException {
+		String humanishName = new URIish("/a/b/c//").getHumanishName();
+		assertEquals("c", humanishName);
+	}
+
+	@Test
+	public void testGetValidGitSchemeWithTwoSlashesHumanishName()
+			throws IllegalArgumentException, URISyntaxException {
+		String humanishName = new URIish(GIT_SCHEME + "/a/b/c//")
+				.getHumanishName();
+		assertEquals("c", humanishName);
+	}
+
+	@Test
 	public void testGetWindowsPathHumanishName()
 			throws IllegalArgumentException,
 			URISyntaxException {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java
index d11edfc..deebe66 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java
@@ -3,6 +3,7 @@
  * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
  * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
  * Copyright (C) 2010, Christian Halstrick <christian.halstrick@sap.com>
+ * Copyright (C) 2013, Robin Stocker <robin@nibor.org>
  * and other copyright owners as documented in the project's IP log.
  *
  * This program and the accompanying materials are made available
@@ -111,7 +112,7 @@ public class URIish implements Serializable {
 	 * Part of a pattern which matches a relative path. Relative paths don't
 	 * start with slash or drive letters. Defines no capturing group.
 	 */
-	private static final String RELATIVE_PATH_P = "(?:(?:[^\\\\/]+[\\\\/])*[^\\\\/]+[\\\\/]?)"; //$NON-NLS-1$
+	private static final String RELATIVE_PATH_P = "(?:(?:[^\\\\/]+[\\\\/]+)*[^\\\\/]+[\\\\/]*)"; //$NON-NLS-1$
 
 	/**
 	 * Part of a pattern which matches a relative or absolute path. Defines no
@@ -698,7 +699,7 @@ public String getHumanishName() throws IllegalArgumentException {
 		if ("file".equals(scheme) || LOCAL_FILE.matcher(s).matches()) //$NON-NLS-1$
 			elements = s.split("[\\" + File.separatorChar + "/]"); //$NON-NLS-1$ //$NON-NLS-2$
 		else
-			elements = s.split("/"); //$NON-NLS-1$
+			elements = s.split("/+"); //$NON-NLS-1$
 		if (elements.length == 0)
 			throw new IllegalArgumentException();
 		String result = elements[elements.length - 1];