@Nullable private String getSingleTargetDir(@NotNull CheckoutRules rules) { Set<String> targetDirs = new HashSet<String>(); for (IncludeRule rule : rules.getRootIncludeRules()) { String from = rule.getFrom(); String to = rule.getTo(); if (from.equals("")) { targetDirs.add(to); continue; } if (from.equals(to)) { targetDirs.add(""); continue; } int prefixEnd = to.lastIndexOf(from); if (prefixEnd == -1) // rule of form +:a=>b, but we don't support such mapping return null; String prefix = to.substring(0, prefixEnd); if (!prefix.endsWith("/")) // rule of form +:a=>ab, but we don't support such mapping return null; prefix = prefix.substring(0, prefix.length() - 1); targetDirs.add(prefix); } if (targetDirs.isEmpty()) return ""; if (targetDirs.size() > 1) // no single target dir return null; return targetDirs.iterator().next(); }
public Collection<VcsClientMapping> getClientMapping( final @NotNull VcsRoot root, final @NotNull IncludeRule rule) throws VcsException { final OperationContext context = createContext(root, "client-mapping"); try { GitVcsRoot gitRoot = context.getGitRoot(); URIish uri = gitRoot.getRepositoryFetchURL(); return Collections.singletonList( new VcsClientMapping( String.format("|%s|%s", uri.toString(), rule.getFrom()), rule.getTo())); } finally { context.close(); } }