You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Transport.java 43KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285
  1. /*
  2. * Copyright (C) 2008-2009, Google Inc.
  3. * Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com>
  4. * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
  5. * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
  6. * and other copyright owners as documented in the project's IP log.
  7. *
  8. * This program and the accompanying materials are made available
  9. * under the terms of the Eclipse Distribution License v1.0 which
  10. * accompanies this distribution, is reproduced below, and is
  11. * available at http://www.eclipse.org/org/documents/edl-v10.php
  12. *
  13. * All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or
  16. * without modification, are permitted provided that the following
  17. * conditions are met:
  18. *
  19. * - Redistributions of source code must retain the above copyright
  20. * notice, this list of conditions and the following disclaimer.
  21. *
  22. * - Redistributions in binary form must reproduce the above
  23. * copyright notice, this list of conditions and the following
  24. * disclaimer in the documentation and/or other materials provided
  25. * with the distribution.
  26. *
  27. * - Neither the name of the Eclipse Foundation, Inc. nor the
  28. * names of its contributors may be used to endorse or promote
  29. * products derived from this software without specific prior
  30. * written permission.
  31. *
  32. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  33. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  34. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  35. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  36. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  37. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  38. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  39. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  40. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  41. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  42. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  43. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  44. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45. */
  46. package org.eclipse.jgit.transport;
  47. import static org.eclipse.jgit.lib.RefDatabase.ALL;
  48. import java.io.BufferedReader;
  49. import java.io.IOException;
  50. import java.io.InputStream;
  51. import java.io.InputStreamReader;
  52. import java.io.OutputStream;
  53. import java.lang.ref.WeakReference;
  54. import java.lang.reflect.Field;
  55. import java.lang.reflect.Modifier;
  56. import java.net.URISyntaxException;
  57. import java.net.URL;
  58. import java.text.MessageFormat;
  59. import java.util.ArrayList;
  60. import java.util.Collection;
  61. import java.util.Collections;
  62. import java.util.Enumeration;
  63. import java.util.HashSet;
  64. import java.util.LinkedList;
  65. import java.util.List;
  66. import java.util.Map;
  67. import java.util.Vector;
  68. import java.util.concurrent.CopyOnWriteArrayList;
  69. import org.eclipse.jgit.errors.NotSupportedException;
  70. import org.eclipse.jgit.errors.TransportException;
  71. import org.eclipse.jgit.internal.JGitText;
  72. import org.eclipse.jgit.lib.Constants;
  73. import org.eclipse.jgit.lib.NullProgressMonitor;
  74. import org.eclipse.jgit.lib.ProgressMonitor;
  75. import org.eclipse.jgit.lib.Ref;
  76. import org.eclipse.jgit.lib.Repository;
  77. import org.eclipse.jgit.storage.pack.PackConfig;
  78. /**
  79. * Connects two Git repositories together and copies objects between them.
  80. * <p>
  81. * A transport can be used for either fetching (copying objects into the
  82. * caller's repository from the remote repository) or pushing (copying objects
  83. * into the remote repository from the caller's repository). Each transport
  84. * implementation is responsible for the details associated with establishing
  85. * the network connection(s) necessary for the copy, as well as actually
  86. * shuffling data back and forth.
  87. * <p>
  88. * Transport instances and the connections they create are not thread-safe.
  89. * Callers must ensure a transport is accessed by only one thread at a time.
  90. */
  91. public abstract class Transport {
  92. /** Type of operation a Transport is being opened for. */
  93. public enum Operation {
  94. /** Transport is to fetch objects locally. */
  95. FETCH,
  96. /** Transport is to push objects remotely. */
  97. PUSH;
  98. }
  99. private static final List<WeakReference<TransportProtocol>> protocols =
  100. new CopyOnWriteArrayList<WeakReference<TransportProtocol>>();
  101. static {
  102. // Registration goes backwards in order of priority.
  103. register(TransportLocal.PROTO_LOCAL);
  104. register(TransportBundleFile.PROTO_BUNDLE);
  105. register(TransportAmazonS3.PROTO_S3);
  106. register(TransportGitAnon.PROTO_GIT);
  107. register(TransportSftp.PROTO_SFTP);
  108. register(TransportHttp.PROTO_FTP);
  109. register(TransportHttp.PROTO_HTTP);
  110. register(TransportGitSsh.PROTO_SSH);
  111. registerByService();
  112. }
  113. private static void registerByService() {
  114. ClassLoader ldr = Thread.currentThread().getContextClassLoader();
  115. if (ldr == null)
  116. ldr = Transport.class.getClassLoader();
  117. Enumeration<URL> catalogs = catalogs(ldr);
  118. while (catalogs.hasMoreElements())
  119. scan(ldr, catalogs.nextElement());
  120. }
  121. private static Enumeration<URL> catalogs(ClassLoader ldr) {
  122. try {
  123. String prefix = "META-INF/services/"; //$NON-NLS-1$
  124. String name = prefix + Transport.class.getName();
  125. return ldr.getResources(name);
  126. } catch (IOException err) {
  127. return new Vector<URL>().elements();
  128. }
  129. }
  130. private static void scan(ClassLoader ldr, URL url) {
  131. BufferedReader br;
  132. try {
  133. InputStream urlIn = url.openStream();
  134. br = new BufferedReader(new InputStreamReader(urlIn, "UTF-8")); //$NON-NLS-1$
  135. } catch (IOException err) {
  136. // If we cannot read from the service list, go to the next.
  137. //
  138. return;
  139. }
  140. try {
  141. String line;
  142. while ((line = br.readLine()) != null) {
  143. line = line.trim();
  144. if (line.length() == 0)
  145. continue;
  146. int comment = line.indexOf('#');
  147. if (comment == 0)
  148. continue;
  149. if (comment != -1)
  150. line = line.substring(0, comment).trim();
  151. load(ldr, line);
  152. }
  153. } catch (IOException err) {
  154. // If we failed during a read, ignore the error.
  155. //
  156. } finally {
  157. try {
  158. br.close();
  159. } catch (IOException e) {
  160. // Ignore the close error; we are only reading.
  161. }
  162. }
  163. }
  164. private static void load(ClassLoader ldr, String cn) {
  165. Class<?> clazz;
  166. try {
  167. clazz = Class.forName(cn, false, ldr);
  168. } catch (ClassNotFoundException notBuiltin) {
  169. // Doesn't exist, even though the service entry is present.
  170. //
  171. return;
  172. }
  173. for (Field f : clazz.getDeclaredFields()) {
  174. if ((f.getModifiers() & Modifier.STATIC) == Modifier.STATIC
  175. && TransportProtocol.class.isAssignableFrom(f.getType())) {
  176. TransportProtocol proto;
  177. try {
  178. proto = (TransportProtocol) f.get(null);
  179. } catch (IllegalArgumentException e) {
  180. // If we cannot access the field, don't.
  181. continue;
  182. } catch (IllegalAccessException e) {
  183. // If we cannot access the field, don't.
  184. continue;
  185. }
  186. if (proto != null)
  187. register(proto);
  188. }
  189. }
  190. }
  191. /**
  192. * Register a TransportProtocol instance for use during open.
  193. * <p>
  194. * Protocol definitions are held by WeakReference, allowing them to be
  195. * garbage collected when the calling application drops all strongly held
  196. * references to the TransportProtocol. Therefore applications should use a
  197. * singleton pattern as described in {@link TransportProtocol}'s class
  198. * documentation to ensure their protocol does not get disabled by garbage
  199. * collection earlier than expected.
  200. * <p>
  201. * The new protocol is registered in front of all earlier protocols, giving
  202. * it higher priority than the built-in protocol definitions.
  203. *
  204. * @param proto
  205. * the protocol definition. Must not be null.
  206. */
  207. public static void register(TransportProtocol proto) {
  208. protocols.add(0, new WeakReference<TransportProtocol>(proto));
  209. }
  210. /**
  211. * Unregister a TransportProtocol instance.
  212. * <p>
  213. * Unregistering a protocol usually isn't necessary, as protocols are held
  214. * by weak references and will automatically clear when they are garbage
  215. * collected by the JVM. Matching is handled by reference equality, so the
  216. * exact reference given to {@link #register(TransportProtocol)} must be
  217. * used.
  218. *
  219. * @param proto
  220. * the exact object previously given to register.
  221. */
  222. public static void unregister(TransportProtocol proto) {
  223. for (WeakReference<TransportProtocol> ref : protocols) {
  224. TransportProtocol refProto = ref.get();
  225. if (refProto == null || refProto == proto)
  226. protocols.remove(ref);
  227. }
  228. }
  229. /**
  230. * Obtain a copy of the registered protocols.
  231. *
  232. * @return an immutable copy of the currently registered protocols.
  233. */
  234. public static List<TransportProtocol> getTransportProtocols() {
  235. int cnt = protocols.size();
  236. List<TransportProtocol> res = new ArrayList<TransportProtocol>(cnt);
  237. for (WeakReference<TransportProtocol> ref : protocols) {
  238. TransportProtocol proto = ref.get();
  239. if (proto != null)
  240. res.add(proto);
  241. else
  242. protocols.remove(ref);
  243. }
  244. return Collections.unmodifiableList(res);
  245. }
  246. /**
  247. * Open a new transport instance to connect two repositories.
  248. * <p>
  249. * This method assumes {@link Operation#FETCH}.
  250. *
  251. * @param local
  252. * existing local repository.
  253. * @param remote
  254. * location of the remote repository - may be URI or remote
  255. * configuration name.
  256. * @return the new transport instance. Never null. In case of multiple URIs
  257. * in remote configuration, only the first is chosen.
  258. * @throws URISyntaxException
  259. * the location is not a remote defined in the configuration
  260. * file and is not a well-formed URL.
  261. * @throws NotSupportedException
  262. * the protocol specified is not supported.
  263. * @throws TransportException
  264. * the transport cannot open this URI.
  265. */
  266. public static Transport open(final Repository local, final String remote)
  267. throws NotSupportedException, URISyntaxException,
  268. TransportException {
  269. return open(local, remote, Operation.FETCH);
  270. }
  271. /**
  272. * Open a new transport instance to connect two repositories.
  273. *
  274. * @param local
  275. * existing local repository.
  276. * @param remote
  277. * location of the remote repository - may be URI or remote
  278. * configuration name.
  279. * @param op
  280. * planned use of the returned Transport; the URI may differ
  281. * based on the type of connection desired.
  282. * @return the new transport instance. Never null. In case of multiple URIs
  283. * in remote configuration, only the first is chosen.
  284. * @throws URISyntaxException
  285. * the location is not a remote defined in the configuration
  286. * file and is not a well-formed URL.
  287. * @throws NotSupportedException
  288. * the protocol specified is not supported.
  289. * @throws TransportException
  290. * the transport cannot open this URI.
  291. */
  292. public static Transport open(final Repository local, final String remote,
  293. final Operation op) throws NotSupportedException,
  294. URISyntaxException, TransportException {
  295. if (local != null) {
  296. final RemoteConfig cfg = new RemoteConfig(local.getConfig(), remote);
  297. if (doesNotExist(cfg))
  298. return open(local, new URIish(remote), null);
  299. return open(local, cfg, op);
  300. } else
  301. return open(new URIish(remote));
  302. }
  303. /**
  304. * Open new transport instances to connect two repositories.
  305. * <p>
  306. * This method assumes {@link Operation#FETCH}.
  307. *
  308. * @param local
  309. * existing local repository.
  310. * @param remote
  311. * location of the remote repository - may be URI or remote
  312. * configuration name.
  313. * @return the list of new transport instances for every URI in remote
  314. * configuration.
  315. * @throws URISyntaxException
  316. * the location is not a remote defined in the configuration
  317. * file and is not a well-formed URL.
  318. * @throws NotSupportedException
  319. * the protocol specified is not supported.
  320. * @throws TransportException
  321. * the transport cannot open this URI.
  322. */
  323. public static List<Transport> openAll(final Repository local,
  324. final String remote) throws NotSupportedException,
  325. URISyntaxException, TransportException {
  326. return openAll(local, remote, Operation.FETCH);
  327. }
  328. /**
  329. * Open new transport instances to connect two repositories.
  330. *
  331. * @param local
  332. * existing local repository.
  333. * @param remote
  334. * location of the remote repository - may be URI or remote
  335. * configuration name.
  336. * @param op
  337. * planned use of the returned Transport; the URI may differ
  338. * based on the type of connection desired.
  339. * @return the list of new transport instances for every URI in remote
  340. * configuration.
  341. * @throws URISyntaxException
  342. * the location is not a remote defined in the configuration
  343. * file and is not a well-formed URL.
  344. * @throws NotSupportedException
  345. * the protocol specified is not supported.
  346. * @throws TransportException
  347. * the transport cannot open this URI.
  348. */
  349. public static List<Transport> openAll(final Repository local,
  350. final String remote, final Operation op)
  351. throws NotSupportedException, URISyntaxException,
  352. TransportException {
  353. final RemoteConfig cfg = new RemoteConfig(local.getConfig(), remote);
  354. if (doesNotExist(cfg)) {
  355. final ArrayList<Transport> transports = new ArrayList<Transport>(1);
  356. transports.add(open(local, new URIish(remote), null));
  357. return transports;
  358. }
  359. return openAll(local, cfg, op);
  360. }
  361. /**
  362. * Open a new transport instance to connect two repositories.
  363. * <p>
  364. * This method assumes {@link Operation#FETCH}.
  365. *
  366. * @param local
  367. * existing local repository.
  368. * @param cfg
  369. * configuration describing how to connect to the remote
  370. * repository.
  371. * @return the new transport instance. Never null. In case of multiple URIs
  372. * in remote configuration, only the first is chosen.
  373. * @throws NotSupportedException
  374. * the protocol specified is not supported.
  375. * @throws TransportException
  376. * the transport cannot open this URI.
  377. * @throws IllegalArgumentException
  378. * if provided remote configuration doesn't have any URI
  379. * associated.
  380. */
  381. public static Transport open(final Repository local, final RemoteConfig cfg)
  382. throws NotSupportedException, TransportException {
  383. return open(local, cfg, Operation.FETCH);
  384. }
  385. /**
  386. * Open a new transport instance to connect two repositories.
  387. *
  388. * @param local
  389. * existing local repository.
  390. * @param cfg
  391. * configuration describing how to connect to the remote
  392. * repository.
  393. * @param op
  394. * planned use of the returned Transport; the URI may differ
  395. * based on the type of connection desired.
  396. * @return the new transport instance. Never null. In case of multiple URIs
  397. * in remote configuration, only the first is chosen.
  398. * @throws NotSupportedException
  399. * the protocol specified is not supported.
  400. * @throws TransportException
  401. * the transport cannot open this URI.
  402. * @throws IllegalArgumentException
  403. * if provided remote configuration doesn't have any URI
  404. * associated.
  405. */
  406. public static Transport open(final Repository local,
  407. final RemoteConfig cfg, final Operation op)
  408. throws NotSupportedException, TransportException {
  409. final List<URIish> uris = getURIs(cfg, op);
  410. if (uris.isEmpty())
  411. throw new IllegalArgumentException(MessageFormat.format(
  412. JGitText.get().remoteConfigHasNoURIAssociated, cfg.getName()));
  413. final Transport tn = open(local, uris.get(0), cfg.getName());
  414. tn.applyConfig(cfg);
  415. return tn;
  416. }
  417. /**
  418. * Open new transport instances to connect two repositories.
  419. * <p>
  420. * This method assumes {@link Operation#FETCH}.
  421. *
  422. * @param local
  423. * existing local repository.
  424. * @param cfg
  425. * configuration describing how to connect to the remote
  426. * repository.
  427. * @return the list of new transport instances for every URI in remote
  428. * configuration.
  429. * @throws NotSupportedException
  430. * the protocol specified is not supported.
  431. * @throws TransportException
  432. * the transport cannot open this URI.
  433. */
  434. public static List<Transport> openAll(final Repository local,
  435. final RemoteConfig cfg) throws NotSupportedException,
  436. TransportException {
  437. return openAll(local, cfg, Operation.FETCH);
  438. }
  439. /**
  440. * Open new transport instances to connect two repositories.
  441. *
  442. * @param local
  443. * existing local repository.
  444. * @param cfg
  445. * configuration describing how to connect to the remote
  446. * repository.
  447. * @param op
  448. * planned use of the returned Transport; the URI may differ
  449. * based on the type of connection desired.
  450. * @return the list of new transport instances for every URI in remote
  451. * configuration.
  452. * @throws NotSupportedException
  453. * the protocol specified is not supported.
  454. * @throws TransportException
  455. * the transport cannot open this URI.
  456. */
  457. public static List<Transport> openAll(final Repository local,
  458. final RemoteConfig cfg, final Operation op)
  459. throws NotSupportedException, TransportException {
  460. final List<URIish> uris = getURIs(cfg, op);
  461. final List<Transport> transports = new ArrayList<Transport>(uris.size());
  462. for (final URIish uri : uris) {
  463. final Transport tn = open(local, uri, cfg.getName());
  464. tn.applyConfig(cfg);
  465. transports.add(tn);
  466. }
  467. return transports;
  468. }
  469. private static List<URIish> getURIs(final RemoteConfig cfg,
  470. final Operation op) {
  471. switch (op) {
  472. case FETCH:
  473. return cfg.getURIs();
  474. case PUSH: {
  475. List<URIish> uris = cfg.getPushURIs();
  476. if (uris.isEmpty())
  477. uris = cfg.getURIs();
  478. return uris;
  479. }
  480. default:
  481. throw new IllegalArgumentException(op.toString());
  482. }
  483. }
  484. private static boolean doesNotExist(final RemoteConfig cfg) {
  485. return cfg.getURIs().isEmpty() && cfg.getPushURIs().isEmpty();
  486. }
  487. /**
  488. * Open a new transport instance to connect two repositories.
  489. *
  490. * @param local
  491. * existing local repository.
  492. * @param uri
  493. * location of the remote repository.
  494. * @return the new transport instance. Never null.
  495. * @throws NotSupportedException
  496. * the protocol specified is not supported.
  497. * @throws TransportException
  498. * the transport cannot open this URI.
  499. */
  500. public static Transport open(final Repository local, final URIish uri)
  501. throws NotSupportedException, TransportException {
  502. return open(local, uri, null);
  503. }
  504. /**
  505. * Open a new transport instance to connect two repositories.
  506. *
  507. * @param local
  508. * existing local repository.
  509. * @param uri
  510. * location of the remote repository.
  511. * @param remoteName
  512. * name of the remote, if the remote as configured in
  513. * {@code local}; otherwise null.
  514. * @return the new transport instance. Never null.
  515. * @throws NotSupportedException
  516. * the protocol specified is not supported.
  517. * @throws TransportException
  518. * the transport cannot open this URI.
  519. */
  520. public static Transport open(Repository local, URIish uri, String remoteName)
  521. throws NotSupportedException, TransportException {
  522. for (WeakReference<TransportProtocol> ref : protocols) {
  523. TransportProtocol proto = ref.get();
  524. if (proto == null) {
  525. protocols.remove(ref);
  526. continue;
  527. }
  528. if (proto.canHandle(uri, local, remoteName))
  529. return proto.open(uri, local, remoteName);
  530. }
  531. throw new NotSupportedException(MessageFormat.format(JGitText.get().URINotSupported, uri));
  532. }
  533. /**
  534. * Open a new transport with no local repository.
  535. * <p>
  536. * Note that the resulting transport instance can not be used for fetching
  537. * or pushing, but only for reading remote refs.
  538. *
  539. * @param uri
  540. * @return new Transport instance
  541. * @throws NotSupportedException
  542. * @throws TransportException
  543. */
  544. public static Transport open(URIish uri) throws NotSupportedException, TransportException {
  545. for (WeakReference<TransportProtocol> ref : protocols) {
  546. TransportProtocol proto = ref.get();
  547. if (proto == null) {
  548. protocols.remove(ref);
  549. continue;
  550. }
  551. if (proto.canHandle(uri, null, null))
  552. return proto.open(uri);
  553. }
  554. throw new NotSupportedException(MessageFormat.format(JGitText.get().URINotSupported, uri));
  555. }
  556. /**
  557. * Convert push remote refs update specification from {@link RefSpec} form
  558. * to {@link RemoteRefUpdate}. Conversion expands wildcards by matching
  559. * source part to local refs. expectedOldObjectId in RemoteRefUpdate is
  560. * always set as null. Tracking branch is configured if RefSpec destination
  561. * matches source of any fetch ref spec for this transport remote
  562. * configuration.
  563. *
  564. * @param db
  565. * local database.
  566. * @param specs
  567. * collection of RefSpec to convert.
  568. * @param fetchSpecs
  569. * fetch specifications used for finding localtracking refs. May
  570. * be null or empty collection.
  571. * @return collection of set up {@link RemoteRefUpdate}.
  572. * @throws IOException
  573. * when problem occurred during conversion or specification set
  574. * up: most probably, missing objects or refs.
  575. */
  576. public static Collection<RemoteRefUpdate> findRemoteRefUpdatesFor(
  577. final Repository db, final Collection<RefSpec> specs,
  578. Collection<RefSpec> fetchSpecs) throws IOException {
  579. if (fetchSpecs == null)
  580. fetchSpecs = Collections.emptyList();
  581. final List<RemoteRefUpdate> result = new LinkedList<RemoteRefUpdate>();
  582. final Collection<RefSpec> procRefs = expandPushWildcardsFor(db, specs);
  583. for (final RefSpec spec : procRefs) {
  584. String srcSpec = spec.getSource();
  585. final Ref srcRef = db.getRef(srcSpec);
  586. if (srcRef != null)
  587. srcSpec = srcRef.getName();
  588. String destSpec = spec.getDestination();
  589. if (destSpec == null) {
  590. // No destination (no-colon in ref-spec), DWIMery assumes src
  591. //
  592. destSpec = srcSpec;
  593. }
  594. if (srcRef != null && !destSpec.startsWith(Constants.R_REFS)) {
  595. // Assume the same kind of ref at the destination, e.g.
  596. // "refs/heads/foo:master", DWIMery assumes master is also
  597. // under "refs/heads/".
  598. //
  599. final String n = srcRef.getName();
  600. final int kindEnd = n.indexOf('/', Constants.R_REFS.length());
  601. destSpec = n.substring(0, kindEnd + 1) + destSpec;
  602. }
  603. final boolean forceUpdate = spec.isForceUpdate();
  604. final String localName = findTrackingRefName(destSpec, fetchSpecs);
  605. final RemoteRefUpdate rru = new RemoteRefUpdate(db, srcSpec,
  606. destSpec, forceUpdate, localName, null);
  607. result.add(rru);
  608. }
  609. return result;
  610. }
  611. private static Collection<RefSpec> expandPushWildcardsFor(
  612. final Repository db, final Collection<RefSpec> specs)
  613. throws IOException {
  614. final Map<String, Ref> localRefs = db.getRefDatabase().getRefs(ALL);
  615. final Collection<RefSpec> procRefs = new HashSet<RefSpec>();
  616. for (final RefSpec spec : specs) {
  617. if (spec.isWildcard()) {
  618. for (final Ref localRef : localRefs.values()) {
  619. if (spec.matchSource(localRef))
  620. procRefs.add(spec.expandFromSource(localRef));
  621. }
  622. } else {
  623. procRefs.add(spec);
  624. }
  625. }
  626. return procRefs;
  627. }
  628. private static String findTrackingRefName(final String remoteName,
  629. final Collection<RefSpec> fetchSpecs) {
  630. // try to find matching tracking refs
  631. for (final RefSpec fetchSpec : fetchSpecs) {
  632. if (fetchSpec.matchSource(remoteName)) {
  633. if (fetchSpec.isWildcard())
  634. return fetchSpec.expandFromSource(remoteName)
  635. .getDestination();
  636. else
  637. return fetchSpec.getDestination();
  638. }
  639. }
  640. return null;
  641. }
  642. /**
  643. * Default setting for {@link #fetchThin} option.
  644. */
  645. public static final boolean DEFAULT_FETCH_THIN = true;
  646. /**
  647. * Default setting for {@link #pushThin} option.
  648. */
  649. public static final boolean DEFAULT_PUSH_THIN = false;
  650. /**
  651. * Specification for fetch or push operations, to fetch or push all tags.
  652. * Acts as --tags.
  653. */
  654. public static final RefSpec REFSPEC_TAGS = new RefSpec(
  655. "refs/tags/*:refs/tags/*"); //$NON-NLS-1$
  656. /**
  657. * Specification for push operation, to push all refs under refs/heads. Acts
  658. * as --all.
  659. */
  660. public static final RefSpec REFSPEC_PUSH_ALL = new RefSpec(
  661. "refs/heads/*:refs/heads/*"); //$NON-NLS-1$
  662. /** The repository this transport fetches into, or pushes out of. */
  663. protected final Repository local;
  664. /** The URI used to create this transport. */
  665. protected final URIish uri;
  666. /** Name of the upload pack program, if it must be executed. */
  667. private String optionUploadPack = RemoteConfig.DEFAULT_UPLOAD_PACK;
  668. /** Specifications to apply during fetch. */
  669. private List<RefSpec> fetch = Collections.emptyList();
  670. /**
  671. * How {@link #fetch(ProgressMonitor, Collection)} should handle tags.
  672. * <p>
  673. * We default to {@link TagOpt#NO_TAGS} so as to avoid fetching annotated
  674. * tags during one-shot fetches used for later merges. This prevents
  675. * dragging down tags from repositories that we do not have established
  676. * tracking branches for. If we do not track the source repository, we most
  677. * likely do not care about any tags it publishes.
  678. */
  679. private TagOpt tagopt = TagOpt.NO_TAGS;
  680. /** Should fetch request thin-pack if remote repository can produce it. */
  681. private boolean fetchThin = DEFAULT_FETCH_THIN;
  682. /** Name of the receive pack program, if it must be executed. */
  683. private String optionReceivePack = RemoteConfig.DEFAULT_RECEIVE_PACK;
  684. /** Specifications to apply during push. */
  685. private List<RefSpec> push = Collections.emptyList();
  686. /** Should push produce thin-pack when sending objects to remote repository. */
  687. private boolean pushThin = DEFAULT_PUSH_THIN;
  688. /** Should push just check for operation result, not really push. */
  689. private boolean dryRun;
  690. /** Should an incoming (fetch) transfer validate objects? */
  691. private boolean checkFetchedObjects;
  692. /** Should refs no longer on the source be pruned from the destination? */
  693. private boolean removeDeletedRefs;
  694. /** Timeout in seconds to wait before aborting an IO read or write. */
  695. private int timeout;
  696. /** Pack configuration used by this transport to make pack file. */
  697. private PackConfig packConfig;
  698. /** Assists with authentication the connection. */
  699. private CredentialsProvider credentialsProvider;
  700. /**
  701. * Create a new transport instance.
  702. *
  703. * @param local
  704. * the repository this instance will fetch into, or push out of.
  705. * This must be the repository passed to
  706. * {@link #open(Repository, URIish)}.
  707. * @param uri
  708. * the URI used to access the remote repository. This must be the
  709. * URI passed to {@link #open(Repository, URIish)}.
  710. */
  711. protected Transport(final Repository local, final URIish uri) {
  712. final TransferConfig tc = local.getConfig().get(TransferConfig.KEY);
  713. this.local = local;
  714. this.uri = uri;
  715. this.checkFetchedObjects = tc.isFsckObjects();
  716. this.credentialsProvider = CredentialsProvider.getDefault();
  717. }
  718. /**
  719. * Create a minimal transport instance not tied to a single repository.
  720. *
  721. * @param uri
  722. */
  723. protected Transport(final URIish uri) {
  724. this.uri = uri;
  725. this.local = null;
  726. this.checkFetchedObjects = true;
  727. this.credentialsProvider = CredentialsProvider.getDefault();
  728. }
  729. /**
  730. * Get the URI this transport connects to.
  731. * <p>
  732. * Each transport instance connects to at most one URI at any point in time.
  733. *
  734. * @return the URI describing the location of the remote repository.
  735. */
  736. public URIish getURI() {
  737. return uri;
  738. }
  739. /**
  740. * Get the name of the remote executable providing upload-pack service.
  741. *
  742. * @return typically "git-upload-pack".
  743. */
  744. public String getOptionUploadPack() {
  745. return optionUploadPack;
  746. }
  747. /**
  748. * Set the name of the remote executable providing upload-pack services.
  749. *
  750. * @param where
  751. * name of the executable.
  752. */
  753. public void setOptionUploadPack(final String where) {
  754. if (where != null && where.length() > 0)
  755. optionUploadPack = where;
  756. else
  757. optionUploadPack = RemoteConfig.DEFAULT_UPLOAD_PACK;
  758. }
  759. /**
  760. * Get the description of how annotated tags should be treated during fetch.
  761. *
  762. * @return option indicating the behavior of annotated tags in fetch.
  763. */
  764. public TagOpt getTagOpt() {
  765. return tagopt;
  766. }
  767. /**
  768. * Set the description of how annotated tags should be treated on fetch.
  769. *
  770. * @param option
  771. * method to use when handling annotated tags.
  772. */
  773. public void setTagOpt(final TagOpt option) {
  774. tagopt = option != null ? option : TagOpt.AUTO_FOLLOW;
  775. }
  776. /**
  777. * Default setting is: {@link #DEFAULT_FETCH_THIN}
  778. *
  779. * @return true if fetch should request thin-pack when possible; false
  780. * otherwise
  781. * @see PackTransport
  782. */
  783. public boolean isFetchThin() {
  784. return fetchThin;
  785. }
  786. /**
  787. * Set the thin-pack preference for fetch operation. Default setting is:
  788. * {@link #DEFAULT_FETCH_THIN}
  789. *
  790. * @param fetchThin
  791. * true when fetch should request thin-pack when possible; false
  792. * when it shouldn't
  793. * @see PackTransport
  794. */
  795. public void setFetchThin(final boolean fetchThin) {
  796. this.fetchThin = fetchThin;
  797. }
  798. /**
  799. * @return true if fetch will verify received objects are formatted
  800. * correctly. Validating objects requires more CPU time on the
  801. * client side of the connection.
  802. */
  803. public boolean isCheckFetchedObjects() {
  804. return checkFetchedObjects;
  805. }
  806. /**
  807. * @param check
  808. * true to enable checking received objects; false to assume all
  809. * received objects are valid.
  810. */
  811. public void setCheckFetchedObjects(final boolean check) {
  812. checkFetchedObjects = check;
  813. }
  814. /**
  815. * Default setting is: {@link RemoteConfig#DEFAULT_RECEIVE_PACK}
  816. *
  817. * @return remote executable providing receive-pack service for pack
  818. * transports.
  819. * @see PackTransport
  820. */
  821. public String getOptionReceivePack() {
  822. return optionReceivePack;
  823. }
  824. /**
  825. * Set remote executable providing receive-pack service for pack transports.
  826. * Default setting is: {@link RemoteConfig#DEFAULT_RECEIVE_PACK}
  827. *
  828. * @param optionReceivePack
  829. * remote executable, if null or empty default one is set;
  830. */
  831. public void setOptionReceivePack(String optionReceivePack) {
  832. if (optionReceivePack != null && optionReceivePack.length() > 0)
  833. this.optionReceivePack = optionReceivePack;
  834. else
  835. this.optionReceivePack = RemoteConfig.DEFAULT_RECEIVE_PACK;
  836. }
  837. /**
  838. * Default setting is: {@value #DEFAULT_PUSH_THIN}
  839. *
  840. * @return true if push should produce thin-pack in pack transports
  841. * @see PackTransport
  842. */
  843. public boolean isPushThin() {
  844. return pushThin;
  845. }
  846. /**
  847. * Set thin-pack preference for push operation. Default setting is:
  848. * {@value #DEFAULT_PUSH_THIN}
  849. *
  850. * @param pushThin
  851. * true when push should produce thin-pack in pack transports;
  852. * false when it shouldn't
  853. * @see PackTransport
  854. */
  855. public void setPushThin(final boolean pushThin) {
  856. this.pushThin = pushThin;
  857. }
  858. /**
  859. * @return true if destination refs should be removed if they no longer
  860. * exist at the source repository.
  861. */
  862. public boolean isRemoveDeletedRefs() {
  863. return removeDeletedRefs;
  864. }
  865. /**
  866. * Set whether or not to remove refs which no longer exist in the source.
  867. * <p>
  868. * If true, refs at the destination repository (local for fetch, remote for
  869. * push) are deleted if they no longer exist on the source side (remote for
  870. * fetch, local for push).
  871. * <p>
  872. * False by default, as this may cause data to become unreachable, and
  873. * eventually be deleted on the next GC.
  874. *
  875. * @param remove true to remove refs that no longer exist.
  876. */
  877. public void setRemoveDeletedRefs(final boolean remove) {
  878. removeDeletedRefs = remove;
  879. }
  880. /**
  881. * Apply provided remote configuration on this transport.
  882. *
  883. * @param cfg
  884. * configuration to apply on this transport.
  885. */
  886. public void applyConfig(final RemoteConfig cfg) {
  887. setOptionUploadPack(cfg.getUploadPack());
  888. setOptionReceivePack(cfg.getReceivePack());
  889. setTagOpt(cfg.getTagOpt());
  890. fetch = cfg.getFetchRefSpecs();
  891. push = cfg.getPushRefSpecs();
  892. timeout = cfg.getTimeout();
  893. }
  894. /**
  895. * @return true if push operation should just check for possible result and
  896. * not really update remote refs, false otherwise - when push should
  897. * act normally.
  898. */
  899. public boolean isDryRun() {
  900. return dryRun;
  901. }
  902. /**
  903. * Set dry run option for push operation.
  904. *
  905. * @param dryRun
  906. * true if push operation should just check for possible result
  907. * and not really update remote refs, false otherwise - when push
  908. * should act normally.
  909. */
  910. public void setDryRun(final boolean dryRun) {
  911. this.dryRun = dryRun;
  912. }
  913. /** @return timeout (in seconds) before aborting an IO operation. */
  914. public int getTimeout() {
  915. return timeout;
  916. }
  917. /**
  918. * Set the timeout before willing to abort an IO call.
  919. *
  920. * @param seconds
  921. * number of seconds to wait (with no data transfer occurring)
  922. * before aborting an IO read or write operation with this
  923. * remote.
  924. */
  925. public void setTimeout(final int seconds) {
  926. timeout = seconds;
  927. }
  928. /**
  929. * Get the configuration used by the pack generator to make packs.
  930. *
  931. * If {@link #setPackConfig(PackConfig)} was previously given null a new
  932. * PackConfig is created on demand by this method using the source
  933. * repository's settings.
  934. *
  935. * @return the pack configuration. Never null.
  936. */
  937. public PackConfig getPackConfig() {
  938. if (packConfig == null)
  939. packConfig = new PackConfig(local);
  940. return packConfig;
  941. }
  942. /**
  943. * Set the configuration used by the pack generator.
  944. *
  945. * @param pc
  946. * configuration controlling packing parameters. If null the
  947. * source repository's settings will be used.
  948. */
  949. public void setPackConfig(PackConfig pc) {
  950. packConfig = pc;
  951. }
  952. /**
  953. * A credentials provider to assist with authentication connections..
  954. *
  955. * @param credentialsProvider
  956. * the credentials provider, or null if there is none
  957. */
  958. public void setCredentialsProvider(CredentialsProvider credentialsProvider) {
  959. this.credentialsProvider = credentialsProvider;
  960. }
  961. /**
  962. * The configured credentials provider.
  963. *
  964. * @return the credentials provider, or null if no credentials provider is
  965. * associated with this transport.
  966. */
  967. public CredentialsProvider getCredentialsProvider() {
  968. return credentialsProvider;
  969. }
  970. /**
  971. * Fetch objects and refs from the remote repository to the local one.
  972. * <p>
  973. * This is a utility function providing standard fetch behavior. Local
  974. * tracking refs associated with the remote repository are automatically
  975. * updated if this transport was created from a {@link RemoteConfig} with
  976. * fetch RefSpecs defined.
  977. *
  978. * @param monitor
  979. * progress monitor to inform the user about our processing
  980. * activity. Must not be null. Use {@link NullProgressMonitor} if
  981. * progress updates are not interesting or necessary.
  982. * @param toFetch
  983. * specification of refs to fetch locally. May be null or the
  984. * empty collection to use the specifications from the
  985. * RemoteConfig. Source for each RefSpec can't be null.
  986. * @return information describing the tracking refs updated.
  987. * @throws NotSupportedException
  988. * this transport implementation does not support fetching
  989. * objects.
  990. * @throws TransportException
  991. * the remote connection could not be established or object
  992. * copying (if necessary) failed or update specification was
  993. * incorrect.
  994. */
  995. public FetchResult fetch(final ProgressMonitor monitor,
  996. Collection<RefSpec> toFetch) throws NotSupportedException,
  997. TransportException {
  998. if (toFetch == null || toFetch.isEmpty()) {
  999. // If the caller did not ask for anything use the defaults.
  1000. //
  1001. if (fetch.isEmpty())
  1002. throw new TransportException(JGitText.get().nothingToFetch);
  1003. toFetch = fetch;
  1004. } else if (!fetch.isEmpty()) {
  1005. // If the caller asked for something specific without giving
  1006. // us the local tracking branch see if we can update any of
  1007. // the local tracking branches without incurring additional
  1008. // object transfer overheads.
  1009. //
  1010. final Collection<RefSpec> tmp = new ArrayList<RefSpec>(toFetch);
  1011. for (final RefSpec requested : toFetch) {
  1012. final String reqSrc = requested.getSource();
  1013. for (final RefSpec configured : fetch) {
  1014. final String cfgSrc = configured.getSource();
  1015. final String cfgDst = configured.getDestination();
  1016. if (cfgSrc.equals(reqSrc) && cfgDst != null) {
  1017. tmp.add(configured);
  1018. break;
  1019. }
  1020. }
  1021. }
  1022. toFetch = tmp;
  1023. }
  1024. final FetchResult result = new FetchResult();
  1025. new FetchProcess(this, toFetch).execute(monitor, result);
  1026. return result;
  1027. }
  1028. /**
  1029. * Push objects and refs from the local repository to the remote one.
  1030. * <p>
  1031. * This is a utility function providing standard push behavior. It updates
  1032. * remote refs and send there necessary objects according to remote ref
  1033. * update specification. After successful remote ref update, associated
  1034. * locally stored tracking branch is updated if set up accordingly. Detailed
  1035. * operation result is provided after execution.
  1036. * <p>
  1037. * For setting up remote ref update specification from ref spec, see helper
  1038. * method {@link #findRemoteRefUpdatesFor(Collection)}, predefined refspecs
  1039. * ({@link #REFSPEC_TAGS}, {@link #REFSPEC_PUSH_ALL}) or consider using
  1040. * directly {@link RemoteRefUpdate} for more possibilities.
  1041. * <p>
  1042. * When {@link #isDryRun()} is true, result of this operation is just
  1043. * estimation of real operation result, no real action is performed.
  1044. *
  1045. * @see RemoteRefUpdate
  1046. *
  1047. * @param monitor
  1048. * progress monitor to inform the user about our processing
  1049. * activity. Must not be null. Use {@link NullProgressMonitor} if
  1050. * progress updates are not interesting or necessary.
  1051. * @param toPush
  1052. * specification of refs to push. May be null or the empty
  1053. * collection to use the specifications from the RemoteConfig
  1054. * converted by {@link #findRemoteRefUpdatesFor(Collection)}. No
  1055. * more than 1 RemoteRefUpdate with the same remoteName is
  1056. * allowed. These objects are modified during this call.
  1057. * @param out
  1058. * output stream to write messages to
  1059. * @return information about results of remote refs updates, tracking refs
  1060. * updates and refs advertised by remote repository.
  1061. * @throws NotSupportedException
  1062. * this transport implementation does not support pushing
  1063. * objects.
  1064. * @throws TransportException
  1065. * the remote connection could not be established or object
  1066. * copying (if necessary) failed at I/O or protocol level or
  1067. * update specification was incorrect.
  1068. * @since 3.0
  1069. */
  1070. public PushResult push(final ProgressMonitor monitor,
  1071. Collection<RemoteRefUpdate> toPush, OutputStream out)
  1072. throws NotSupportedException,
  1073. TransportException {
  1074. if (toPush == null || toPush.isEmpty()) {
  1075. // If the caller did not ask for anything use the defaults.
  1076. try {
  1077. toPush = findRemoteRefUpdatesFor(push);
  1078. } catch (final IOException e) {
  1079. throw new TransportException(MessageFormat.format(
  1080. JGitText.get().problemWithResolvingPushRefSpecsLocally, e.getMessage()), e);
  1081. }
  1082. if (toPush.isEmpty())
  1083. throw new TransportException(JGitText.get().nothingToPush);
  1084. }
  1085. final PushProcess pushProcess = new PushProcess(this, toPush, out);
  1086. return pushProcess.execute(monitor);
  1087. }
  1088. /**
  1089. * Push objects and refs from the local repository to the remote one.
  1090. * <p>
  1091. * This is a utility function providing standard push behavior. It updates
  1092. * remote refs and sends necessary objects according to remote ref update
  1093. * specification. After successful remote ref update, associated locally
  1094. * stored tracking branch is updated if set up accordingly. Detailed
  1095. * operation result is provided after execution.
  1096. * <p>
  1097. * For setting up remote ref update specification from ref spec, see helper
  1098. * method {@link #findRemoteRefUpdatesFor(Collection)}, predefined refspecs
  1099. * ({@link #REFSPEC_TAGS}, {@link #REFSPEC_PUSH_ALL}) or consider using
  1100. * directly {@link RemoteRefUpdate} for more possibilities.
  1101. * <p>
  1102. * When {@link #isDryRun()} is true, result of this operation is just
  1103. * estimation of real operation result, no real action is performed.
  1104. *
  1105. * @see RemoteRefUpdate
  1106. *
  1107. * @param monitor
  1108. * progress monitor to inform the user about our processing
  1109. * activity. Must not be null. Use {@link NullProgressMonitor} if
  1110. * progress updates are not interesting or necessary.
  1111. * @param toPush
  1112. * specification of refs to push. May be null or the empty
  1113. * collection to use the specifications from the RemoteConfig
  1114. * converted by {@link #findRemoteRefUpdatesFor(Collection)}. No
  1115. * more than 1 RemoteRefUpdate with the same remoteName is
  1116. * allowed. These objects are modified during this call.
  1117. *
  1118. * @return information about results of remote refs updates, tracking refs
  1119. * updates and refs advertised by remote repository.
  1120. * @throws NotSupportedException
  1121. * this transport implementation does not support pushing
  1122. * objects.
  1123. * @throws TransportException
  1124. * the remote connection could not be established or object
  1125. * copying (if necessary) failed at I/O or protocol level or
  1126. * update specification was incorrect.
  1127. */
  1128. public PushResult push(final ProgressMonitor monitor,
  1129. Collection<RemoteRefUpdate> toPush) throws NotSupportedException,
  1130. TransportException {
  1131. return push(monitor, toPush, null);
  1132. }
  1133. /**
  1134. * Convert push remote refs update specification from {@link RefSpec} form
  1135. * to {@link RemoteRefUpdate}. Conversion expands wildcards by matching
  1136. * source part to local refs. expectedOldObjectId in RemoteRefUpdate is
  1137. * always set as null. Tracking branch is configured if RefSpec destination
  1138. * matches source of any fetch ref spec for this transport remote
  1139. * configuration.
  1140. * <p>
  1141. * Conversion is performed for context of this transport (database, fetch
  1142. * specifications).
  1143. *
  1144. * @param specs
  1145. * collection of RefSpec to convert.
  1146. * @return collection of set up {@link RemoteRefUpdate}.
  1147. * @throws IOException
  1148. * when problem occurred during conversion or specification set
  1149. * up: most probably, missing objects or refs.
  1150. */
  1151. public Collection<RemoteRefUpdate> findRemoteRefUpdatesFor(
  1152. final Collection<RefSpec> specs) throws IOException {
  1153. return findRemoteRefUpdatesFor(local, specs, fetch);
  1154. }
  1155. /**
  1156. * Begins a new connection for fetching from the remote repository.
  1157. * <p>
  1158. * If the transport has no local repository, the fetch connection can only
  1159. * be used for reading remote refs.
  1160. *
  1161. * @return a fresh connection to fetch from the remote repository.
  1162. * @throws NotSupportedException
  1163. * the implementation does not support fetching.
  1164. * @throws TransportException
  1165. * the remote connection could not be established.
  1166. */
  1167. public abstract FetchConnection openFetch() throws NotSupportedException,
  1168. TransportException;
  1169. /**
  1170. * Begins a new connection for pushing into the remote repository.
  1171. *
  1172. * @return a fresh connection to push into the remote repository.
  1173. * @throws NotSupportedException
  1174. * the implementation does not support pushing.
  1175. * @throws TransportException
  1176. * the remote connection could not be established
  1177. */
  1178. public abstract PushConnection openPush() throws NotSupportedException,
  1179. TransportException;
  1180. /**
  1181. * Close any resources used by this transport.
  1182. * <p>
  1183. * If the remote repository is contacted by a network socket this method
  1184. * must close that network socket, disconnecting the two peers. If the
  1185. * remote repository is actually local (same system) this method must close
  1186. * any open file handles used to read the "remote" repository.
  1187. */
  1188. public abstract void close();
  1189. }