Create the temporary pack file in the git repo being fetched into
[egit/zawir.git] / org.spearce.jgit / src / org / spearce / jgit / fetch / FullFetchClient.java
blobfecb7ded1b972bf1597fe23243715adccc1688de
1 package org.spearce.jgit.fetch;
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(pi, new File(new File(repository.getObjectsDirectory(), "pack"), "packtmp_pack"+System.currentTimeMillis()));
33 pack.index(monitor);
34 pack.renamePack(repository);
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 repository.scanForPacks();
48 updateRemoteRefs(remote);
49 } catch (InterruptedException e) {
50 if (threadError[0] != null)
51 if (threadError[0] instanceof IOException)
52 throw (IOException)threadError[0];
53 throw new Error(threadError[0]);
54 } finally {
55 if (indexThread.isAlive()) {
56 indexThread.interrupt();
57 try {
58 indexThread.join();
59 } catch (InterruptedException e) {
60 // nothing here
66 /**
67 * Construct a {@link FullFetchClient}
69 * @param repository
70 * @param remoteName
71 * @param initialCommand
72 * @param toServer
73 * @param fromServer
74 * @throws IOException
76 public FullFetchClient(Repository repository, String remoteName, String initialCommand,
77 OutputStream toServer, InputStream fromServer) throws IOException {
78 super(repository, initialCommand, toServer, fromServer, null);
79 remote = remoteName;
80 os = new PipedOutputStream(pi);