Define RemoteConfig and RefSpec objects to parse remote blocks
[egit/zawir.git] / org.spearce.jgit / src / org / spearce / jgit / transport / FullFetchClient.java
blob6c0a7cafffc86a4ecd105367b7784cf3589caa30
1 package org.spearce.jgit.transport;
3 import java.io.File;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.io.OutputStream;
7 import java.io.PipedInputStream;
8 import java.io.PipedOutputStream;
10 import org.spearce.jgit.lib.ProgressMonitor;
11 import org.spearce.jgit.lib.Repository;
13 /**
14 * This is does-it-all fetch implementation.
16 public class FullFetchClient extends FetchClient {
18 private PipedInputStream pi = new PipedInputStream();
19 Throwable[] threadError = new Throwable[1];
20 Thread fetchThread;
21 private String remote;
23 Thread indexThread;
25 public void run(final ProgressMonitor monitor) throws IOException {
26 try {
27 indexThread = new Thread() {
28 @Override
29 public void run() {
30 IndexPack pack;
31 try {
32 pack = new IndexPack(repository, pi, new File(new File(repository.getObjectsDirectory(), "pack"), "packtmp_pack"+System.currentTimeMillis()));
33 pack.index(monitor);
34 pack.renameAndOpenPack();
35 } catch (Throwable e) {
36 e.printStackTrace();
37 fetchThread.interrupt();
38 threadError[0] = e;
42 fetchThread = Thread.currentThread();
43 indexThread.start();
44 super.run(monitor);
45 os.close();
46 indexThread.join();
47 updateRemoteRefs(remote);
48 } catch (InterruptedException e) {
49 if (threadError[0] != null)
50 if (threadError[0] instanceof IOException)
51 throw (IOException)threadError[0];
52 throw new Error(threadError[0]);
53 } finally {
54 if (indexThread.isAlive()) {
55 indexThread.interrupt();
56 try {
57 indexThread.join();
58 } catch (InterruptedException e) {
59 // nothing here
65 /**
66 * Construct a {@link FullFetchClient}
68 * @param repository
69 * @param remoteName
70 * @param initialCommand
71 * @param toServer
72 * @param fromServer
73 * @throws IOException
75 public FullFetchClient(Repository repository, String remoteName, String initialCommand,
76 OutputStream toServer, InputStream fromServer) throws IOException {
77 super(repository, initialCommand, toServer, fromServer, null);
78 remote = remoteName;
79 os = new PipedOutputStream(pi);