Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/HgRemoteRepository.java @ 697:24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 06 Aug 2013 13:34:34 +0200 |
parents | 9859fcea475d |
children | 822f3a83ff57 |
comparison
equal
deleted
inserted
replaced
696:5b5d199e2eb3 | 697:24f4efedc9d5 |
---|---|
21 import static org.tmatesoft.hg.util.Outcome.Kind.Success; | 21 import static org.tmatesoft.hg.util.Outcome.Kind.Success; |
22 | 22 |
23 import java.io.BufferedReader; | 23 import java.io.BufferedReader; |
24 import java.io.ByteArrayOutputStream; | 24 import java.io.ByteArrayOutputStream; |
25 import java.io.File; | 25 import java.io.File; |
26 import java.io.FileOutputStream; | |
27 import java.io.IOException; | 26 import java.io.IOException; |
28 import java.io.InputStream; | 27 import java.io.InputStream; |
29 import java.io.InputStreamReader; | 28 import java.io.InputStreamReader; |
30 import java.io.OutputStream; | 29 import java.io.OutputStream; |
31 import java.io.StreamTokenizer; | 30 import java.io.StreamTokenizer; |
42 import java.util.LinkedHashMap; | 41 import java.util.LinkedHashMap; |
43 import java.util.LinkedList; | 42 import java.util.LinkedList; |
44 import java.util.List; | 43 import java.util.List; |
45 import java.util.Map; | 44 import java.util.Map; |
46 import java.util.Set; | 45 import java.util.Set; |
47 import java.util.zip.InflaterInputStream; | |
48 | 46 |
49 import org.tmatesoft.hg.core.HgBadArgumentException; | 47 import org.tmatesoft.hg.core.HgBadArgumentException; |
50 import org.tmatesoft.hg.core.HgIOException; | 48 import org.tmatesoft.hg.core.HgIOException; |
51 import org.tmatesoft.hg.core.HgRemoteConnectionException; | 49 import org.tmatesoft.hg.core.HgRemoteConnectionException; |
52 import org.tmatesoft.hg.core.HgRepositoryNotFoundException; | 50 import org.tmatesoft.hg.core.HgRepositoryNotFoundException; |
59 import org.tmatesoft.hg.internal.FileUtils; | 57 import org.tmatesoft.hg.internal.FileUtils; |
60 import org.tmatesoft.hg.internal.Internals; | 58 import org.tmatesoft.hg.internal.Internals; |
61 import org.tmatesoft.hg.internal.PropertyMarshal; | 59 import org.tmatesoft.hg.internal.PropertyMarshal; |
62 import org.tmatesoft.hg.internal.remote.Connector; | 60 import org.tmatesoft.hg.internal.remote.Connector; |
63 import org.tmatesoft.hg.internal.remote.HttpConnector; | 61 import org.tmatesoft.hg.internal.remote.HttpConnector; |
62 import org.tmatesoft.hg.internal.remote.SshConnector; | |
64 import org.tmatesoft.hg.util.LogFacility.Severity; | 63 import org.tmatesoft.hg.util.LogFacility.Severity; |
65 import org.tmatesoft.hg.util.Outcome; | 64 import org.tmatesoft.hg.util.Outcome; |
66 import org.tmatesoft.hg.util.Pair; | 65 import org.tmatesoft.hg.util.Pair; |
67 | 66 |
68 /** | 67 /** |
113 if (url == null || ctx == null) { | 112 if (url == null || ctx == null) { |
114 throw new IllegalArgumentException(); | 113 throw new IllegalArgumentException(); |
115 } | 114 } |
116 sessionContext = ctx; | 115 sessionContext = ctx; |
117 debug = new PropertyMarshal(ctx).getBoolean("hg4j.remote.debug", false); | 116 debug = new PropertyMarshal(ctx).getBoolean("hg4j.remote.debug", false); |
118 remote = new HttpConnector(); | 117 remote = "ssh".equals(url.getProtocol()) ? new SshConnector() : new HttpConnector(); |
119 remote.init(url, ctx, null); | 118 remote.init(url, ctx, null); |
120 } | 119 } |
121 | 120 |
122 public boolean isInvalid() throws HgRemoteConnectionException { | 121 public boolean isInvalid() throws HgRemoteConnectionException { |
123 initCapabilities(); | 122 initCapabilities(); |
279 return null; // XXX valid retval??? | 278 return null; // XXX valid retval??? |
280 } | 279 } |
281 List<Nodeid> _roots = roots.isEmpty() ? Collections.singletonList(Nodeid.NULL) : roots; | 280 List<Nodeid> _roots = roots.isEmpty() ? Collections.singletonList(Nodeid.NULL) : roots; |
282 try { | 281 try { |
283 remote.sessionBegin(); | 282 remote.sessionBegin(); |
284 File tf = writeBundle(remote.changegroup(_roots), false, "HG10GZ" /*didn't see any other that zip*/); | 283 File tf = writeBundle(remote.changegroup(_roots)); |
285 if (debug) { | 284 if (debug) { |
286 System.out.printf("Wrote bundle %s for roots %s\n", tf, roots); | 285 System.out.printf("Wrote bundle %s for roots %s\n", tf, roots); |
287 } | 286 } |
288 return getLookupHelper().loadBundle(tf); | 287 return getLookupHelper().loadBundle(tf); |
289 } catch (IOException ex) { | 288 } catch (IOException ex) { |
457 } finally { | 456 } finally { |
458 remote.sessionEnd(); | 457 remote.sessionEnd(); |
459 } | 458 } |
460 } | 459 } |
461 | 460 |
462 private static File writeBundle(InputStream is, boolean decompress, String header) throws IOException { | 461 private File writeBundle(InputStream is) throws IOException { |
463 InputStream zipStream = decompress ? new InflaterInputStream(is) : is; | |
464 File tf = File.createTempFile("hg4j-bundle-", null); | 462 File tf = File.createTempFile("hg4j-bundle-", null); |
465 FileOutputStream fos = new FileOutputStream(tf); | 463 new FileUtils(sessionContext.getLog(), this).write(is, tf); |
466 fos.write(header.getBytes()); | 464 is.close(); |
467 int r; | |
468 byte[] buf = new byte[8*1024]; | |
469 while ((r = zipStream.read(buf)) != -1) { | |
470 fos.write(buf, 0, r); | |
471 } | |
472 fos.close(); | |
473 zipStream.close(); | |
474 return tf; | 465 return tf; |
475 } | 466 } |
476 | 467 |
477 | 468 |
478 public static final class Range { | 469 public static final class Range { |