Mercurial > jhg
comparison src/org/tmatesoft/hg/util/Path.java @ 639:49f0749307a0 smartgit-4.5
Issue 46: Files with backslashes (legal on Linux) cause troubles
(grafted from 170b6ecc890e476f38108067daa3dfffe9758013)
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Thu, 06 Jun 2013 14:21:11 +0200 |
| parents | 072b5f3ed0c8 |
| children | 5d8798772cca |
comparison
equal
deleted
inserted
replaced
| 638:2f1cd1c26de5 | 639:49f0749307a0 |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011-2012 TMate Software Ltd | 2 * Copyright (c) 2011-2013 TMate Software Ltd |
| 3 * | 3 * |
| 4 * This program is free software; you can redistribute it and/or modify | 4 * This program is free software; you can redistribute it and/or modify |
| 5 * it under the terms of the GNU General Public License as published by | 5 * it under the terms of the GNU General Public License as published by |
| 6 * the Free Software Foundation; version 2 of the License. | 6 * the Free Software Foundation; version 2 of the License. |
| 7 * | 7 * |
| 18 | 18 |
| 19 import java.util.Collection; | 19 import java.util.Collection; |
| 20 import java.util.Iterator; | 20 import java.util.Iterator; |
| 21 import java.util.NoSuchElementException; | 21 import java.util.NoSuchElementException; |
| 22 | 22 |
| 23 import org.tmatesoft.hg.internal.Internals; | |
| 24 | |
| 23 /** | 25 /** |
| 24 * Identify repository files (not String nor io.File). Convenient for pattern matching. Memory-friendly. | 26 * Identify repository files (not String nor io.File). Convenient for pattern matching. Memory-friendly. |
| 25 * | 27 * |
| 26 * @author Artem Tikhomirov | 28 * @author Artem Tikhomirov |
| 27 * @author TMate Software Ltd. | 29 * @author TMate Software Ltd. |
| 146 assert p1.startsWith(p2); | 148 assert p1.startsWith(p2); |
| 147 String p1Tail= p1.substring(p2.length()); | 149 String p1Tail= p1.substring(p2.length()); |
| 148 int slashLoc = p1Tail.indexOf('/'); | 150 int slashLoc = p1Tail.indexOf('/'); |
| 149 return slashLoc == -1 || slashLoc == p1Tail.length() - 1; | 151 return slashLoc == -1 || slashLoc == p1Tail.length() - 1; |
| 150 } | 152 } |
| 153 | |
| 154 private static final boolean runningOnWindows; | |
| 155 | |
| 156 static { | |
| 157 runningOnWindows = Internals.runningOnWindows(); | |
| 158 } | |
| 151 | 159 |
| 152 public static Path create(CharSequence path) { | 160 public static Path create(CharSequence path) { |
| 153 if (path == null) { | 161 if (path == null) { |
| 154 throw new IllegalArgumentException(); | 162 throw new IllegalArgumentException(); |
| 155 } | 163 } |
| 156 if (path instanceof Path) { | 164 if (path instanceof Path) { |
| 157 Path o = (Path) path; | 165 Path o = (Path) path; |
| 158 return o; | 166 return o; |
| 159 } | 167 } |
| 160 String p = path.toString(); | 168 String p = path.toString(); |
| 161 if (p.indexOf('\\') != -1) { | 169 if (runningOnWindows && p.indexOf('\\') != -1) { |
| 162 throw new IllegalArgumentException(); | 170 throw new IllegalArgumentException(); |
| 163 } | 171 } |
| 164 Path rv = new Path(p); | 172 Path rv = new Path(p); |
| 165 return rv; | 173 return rv; |
| 166 } | 174 } |
