1 /* 2 * Copyright (C) 2010, Google Inc. 3 * Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com> 4 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> and others 5 * 6 * This program and the accompanying materials are made available under the 7 * terms of the Eclipse Distribution License v. 1.0 which is available at 8 * https://www.eclipse.org/org/documents/edl-v10.php. 9 * 10 * SPDX-License-Identifier: BSD-3-Clause 11 */ 12 13 package org.eclipse.jgit.transport; 14 15 import java.util.Collection; 16 import java.util.Map; 17 18 import org.eclipse.jgit.lib.Ref; 19 20 /** 21 * Represent connection for operation on a remote repository. 22 * <p> 23 * Currently all operations on remote repository (fetch and push) provide 24 * information about remote refs. Every connection is able to be closed and 25 * should be closed - this is a connection client responsibility. 26 * 27 * @see Transport 28 */ 29 public interface Connection extends AutoCloseable { 30 /** 31 * Get the complete map of refs advertised as available for fetching or 32 * pushing. 33 * 34 * @return available/advertised refs: map of refname to ref. Never null. Not 35 * modifiable. The collection can be empty if the remote side has no 36 * refs (it is an empty/newly created repository). 37 */ 38 Map<String, Ref> getRefsMap(); 39 40 /** 41 * Get the complete list of refs advertised as available for fetching or 42 * pushing. 43 * <p> 44 * The returned refs may appear in any order. If the caller needs these to 45 * be sorted, they should be copied into a new array or List and then sorted 46 * by the caller as necessary. 47 * 48 * @return available/advertised refs. Never null. Not modifiable. The 49 * collection can be empty if the remote side has no refs (it is an 50 * empty/newly created repository). 51 */ 52 Collection<Ref> getRefs(); 53 54 /** 55 * Get a single advertised ref by name. 56 * <p> 57 * The name supplied should be valid ref name. To get a peeled value for a 58 * ref (aka <code>refs/tags/v1.0^{}</code>) use the base name (without 59 * the <code>^{}</code> suffix) and look at the peeled object id. 60 * 61 * @param name 62 * name of the ref to obtain. 63 * @return the requested ref; null if the remote did not advertise this ref. 64 */ 65 Ref getRef(String name); 66 67 /** 68 * {@inheritDoc} 69 * <p> 70 * Close any resources used by this connection. 71 * <p> 72 * If the remote repository is contacted by a network socket this method 73 * must close that network socket, disconnecting the two peers. If the 74 * remote repository is actually local (same system) this method must close 75 * any open file handles used to read the "remote" repository. 76 * <p> 77 * If additional messages were produced by the remote peer, these should 78 * still be retained in the connection instance for {@link #getMessages()}. 79 * <p> 80 * {@code AutoClosable.close()} declares that it throws {@link Exception}. 81 * Implementers shouldn't throw checked exceptions. This override narrows 82 * the signature to prevent them from doing so. 83 */ 84 @Override 85 void close(); 86 87 /** 88 * Get the additional messages, if any, returned by the remote process. 89 * <p> 90 * These messages are most likely informational or error messages, sent by 91 * the remote peer, to help the end-user correct any problems that may have 92 * prevented the operation from completing successfully. Application UIs 93 * should try to show these in an appropriate context. 94 * <p> 95 * The message buffer is available after {@link #close()} has been called. 96 * Prior to closing the connection, the message buffer may be empty. 97 * 98 * @return the messages returned by the remote, most likely terminated by a 99 * newline (LF) character. The empty string is returned if the 100 * remote produced no additional messages. 101 */ 102 String getMessages(); 103 104 /** 105 * User agent advertised by the remote server. 106 * 107 * @return agent (version of Git) running on the remote server. Null if the 108 * server does not advertise this version. 109 * @since 4.0 110 */ 111 String getPeerUserAgent(); 112 }