/** * Creates a message digest * @param uri * @return * @throws NoSuchAlgorithmException */ private static byte[] canonicalRequestDigest(URIish uri) throws NoSuchAlgorithmException { StringBuilder canonicalRequest = new StringBuilder(); canonicalRequest.append("GIT\n") // codecommit uses GIT as the request method .append(uri.getPath()).append("\n") // URI request path .append("\n") // Query string, always empty for codecommit // Next is canonical headers, codecommit only requires the host header .append("host:").append(uri.getHost()).append("\n") .append("\n") // canonical headers are always terminated by newline .append("host\n"); // The list of canonical headers, only one for codecommit MessageDigest digest = MessageDigest.getInstance(SHA_256); return digest.digest(canonicalRequest.toString().getBytes()); }
public static String retrieveProjectId(GitLabClient client, String remoteUrl) throws ProjectIdResolutionException { try { String baseUri = client.getHostUrl(); String projectId; if (baseUri != null && remoteUrl.startsWith(baseUri)) { projectId = new URIish(remoteUrl.substring(baseUri.length())).getPath(); if (projectId.contains(":")) { projectId = projectId.substring(projectId.indexOf(":")); } else if (projectId.startsWith(".")) { projectId = projectId.substring(projectId.indexOf("/")); } } else { projectId = new URIish(remoteUrl).getPath(); } if (projectId.startsWith(":")) { projectId = projectId.substring(1); } Matcher matcher = PROJECT_ID_PATTERN.matcher(projectId); if (matcher.matches()) { return matcher.group("projectId"); } else { throw new ProjectIdResolutionException(String.format("Failed to retrieve GitLab projectId for %s", remoteUrl)); } } catch (URISyntaxException e) { throw new ProjectIdResolutionException(String.format("Failed to retrieve GitLab projectId for %s", remoteUrl), e); } }
String commandFor(String exe) { String path = uri.getPath(); if (uri.getScheme() != null && uri.getPath().startsWith("/~")) //$NON-NLS-1$ path = (uri.getPath().substring(1)); final StringBuilder cmd = new StringBuilder(); cmd.append(exe); cmd.append(' '); cmd.append(QuotedString.BOURNE.quote(path)); return cmd.toString(); }
NoRemoteRepositoryException cleanNotFound(NoRemoteRepositoryException nf, String why) { if (why == null || why.length() == 0) return nf; String path = uri.getPath(); if (uri.getScheme() != null && uri.getPath().startsWith("/~")) //$NON-NLS-1$ path = uri.getPath().substring(1); final StringBuilder pfx = new StringBuilder(); pfx.append("fatal: "); //$NON-NLS-1$ pfx.append(QuotedString.BOURNE.quote(path)); pfx.append(": "); //$NON-NLS-1$ if (why.startsWith(pfx.toString())) why = why.substring(pfx.length()); return new NoRemoteRepositoryException(uri, why); }
@Override public boolean canHandle(URIish uri, Repository local, String remoteName) { if (uri.getScheme() == null) { // scp-style URI "host:path" does not have scheme. return uri.getHost() != null && uri.getPath() != null && uri.getHost().length() != 0 && uri.getPath().length() != 0; } return super.canHandle(uri, local, remoteName); }
TransportAmazonS3(final Repository local, final URIish uri) throws NotSupportedException { super(local, uri); Properties props = loadProperties(); File directory = local.getDirectory(); if (!props.containsKey("tmpdir") && directory != null) //$NON-NLS-1$ props.put("tmpdir", directory.getPath()); //$NON-NLS-1$ s3 = new AmazonS3(props); bucket = uri.getHost(); String p = uri.getPath(); if (p.startsWith("/")) //$NON-NLS-1$ p = p.substring(1); if (p.endsWith("/")) //$NON-NLS-1$ p = p.substring(0, p.length() - 1); keyPrefix = p; }
void service(String name, PacketLineOut pckOut) throws IOException { final StringBuilder cmd = new StringBuilder(); cmd.append(name); cmd.append(' '); cmd.append(uri.getPath()); cmd.append('\0'); cmd.append("host="); //$NON-NLS-1$ cmd.append(uri.getHost()); if (uri.getPort() > 0 && uri.getPort() != GIT_PORT) { cmd.append(":"); //$NON-NLS-1$ cmd.append(uri.getPort()); } cmd.append('\0'); pckOut.writeString(cmd.toString()); pckOut.flush(); }
String s = getPath(); if ("/".equals(s) || "".equals(s)) //$NON-NLS-1$ //$NON-NLS-2$ s = getHost();
@Override public Transport open(URIish uri) throws NotSupportedException, TransportException { if ("bundle".equals(uri.getScheme())) { //$NON-NLS-1$ File path = FS.DETECTED.resolve(new File("."), uri.getPath()); //$NON-NLS-1$ return new TransportBundleFile(uri, path); } return TransportLocal.PROTO_LOCAL.open(uri); } };
@Override public Transport open(URIish uri, Repository local, String remoteName) throws NotSupportedException, TransportException { if ("bundle".equals(uri.getScheme())) { //$NON-NLS-1$ File path = FS.DETECTED.resolve(new File("."), uri.getPath()); //$NON-NLS-1$ return new TransportBundleFile(local, uri, path); } // This is an ambiguous reference, it could be a bundle file // or it could be a Git repository. Allow TransportLocal to // resolve the path and figure out which type it is by testing // the target. // return TransportLocal.PROTO_LOCAL.open(uri, local, remoteName); }
/** {@inheritDoc} */ @Override public int hashCode() { int hc = 0; if (getScheme() != null) hc = hc * 31 + getScheme().hashCode(); if (getUser() != null) hc = hc * 31 + getUser().hashCode(); if (getPass() != null) hc = hc * 31 + getPass().hashCode(); if (getHost() != null) hc = hc * 31 + getHost().hashCode(); if (getPort() > 0) hc = hc * 31 + getPort(); if (getPath() != null) hc = hc * 31 + getPath().hashCode(); return hc; }
if (getPath() != null) { if (getScheme() != null) { if (!getPath().startsWith("/") && !getPath().isEmpty()) //$NON-NLS-1$ r.append('/'); } else if (getHost() != null) if (getScheme() != null) if (escapeNonAscii) r.append(escape(getPath(), false, escapeNonAscii)); else r.append(getRawPath()); else r.append(getPath());
@Override public Transport open(URIish uri) throws NotSupportedException, TransportException { File path = FS.DETECTED.resolve(new File("."), uri.getPath()); //$NON-NLS-1$ // If the reference is to a local file, C Git behavior says // assume this is a bundle, since repositories are directories. if (path.isFile()) return new TransportBundleFile(uri, path); File gitDir = RepositoryCache.FileKey.resolve(path, FS.DETECTED); if (gitDir == null) throw new NoRemoteRepositoryException(uri, JGitText.get().notFound); return new TransportLocal(uri, gitDir); } };
/** {@inheritDoc} */ @Override public FetchConnection openFetch() throws TransportException { final SftpObjectDB c = new SftpObjectDB(uri.getPath()); final WalkFetchConnection r = new WalkFetchConnection(this, c); r.available(c.readAdvertisedRefs()); return r; }
/** {@inheritDoc} */ @Override public PushConnection openPush() throws TransportException { final SftpObjectDB c = new SftpObjectDB(uri.getPath()); final WalkPushConnection r = new WalkPushConnection(this, c); r.available(c.readAdvertisedRefs()); return r; }
@Override public boolean canHandle(URIish uri, Repository local, String remoteName) { if (uri.getPath() == null || uri.getPort() > 0 || uri.getUser() != null || uri.getPass() != null || uri.getHost() != null || (uri.getScheme() != null && !getSchemes().contains(uri.getScheme()))) return false; return true; }
@Override public boolean canHandle(URIish uri, Repository local, String remoteName) { if (uri.getPath() == null || uri.getPort() > 0 || uri.getUser() != null || uri.getPass() != null || uri.getHost() != null || (uri.getScheme() != null && !getSchemes().contains(uri.getScheme()))) return false; return true; }
@Override public Transport open(URIish uri, Repository local, String remoteName) throws NoRemoteRepositoryException { File localPath = local.isBare() ? local.getDirectory() : local.getWorkTree(); File path = local.getFS().resolve(localPath, uri.getPath()); // If the reference is to a local file, C Git behavior says // assume this is a bundle, since repositories are directories. if (path.isFile()) return new TransportBundleFile(local, uri, path); File gitDir = RepositoryCache.FileKey.resolve(path, local.getFS()); if (gitDir == null) throw new NoRemoteRepositoryException(uri, JGitText.get().notFound); return new TransportLocal(local, uri, gitDir); }
/** {@inheritDoc} */ @Override public boolean equals(Object obj) { if (!(obj instanceof URIish)) return false; final URIish b = (URIish) obj; if (!eq(getScheme(), b.getScheme())) return false; if (!eq(getUser(), b.getUser())) return false; if (!eq(getPass(), b.getPass())) return false; if (!eq(getHost(), b.getHost())) return false; if (getPort() != b.getPort()) return false; if (!eq(getPath(), b.getPath())) return false; return true; }